Consider the following example that takes a msg
and posts it asynchronously.
void sendMessage(std::string msg) {
runAsync<void>([msg = std::move(msg)] {
onPostMessage(cookie, msg.c_str());
});
};
Would the following be faster?
void sendMessage(std::string&& msg) {
What would be the best options at the calling site?
auto msg = ...
postMessage(msg);
or
auto msg = ...
postMessage(std::move(msg));
Note that msg
isn't needed after the call anymore.
Will the compiler automatically detect that I am not using msg
anymore after the call and "move" it?