Pass string parameter to callback function in C++11
<p>Suppose I have a callback function taking a string parameter.
This callback function is invoked with a string object that is no longer needed at call site, and most likely this function will need to do some string processing.
What would you suggest to use for the parameter - lvalue reference, rvalue reference, or const lvalue reference, or something else?</p>

<p>a. If I am concerned about achieving maximum performance.</p>

<p>b. If I am concerned about code clarity.</p>

<pre><code>CallbackType callback = processMessage; // declared elsewhere

std::string message;

// Way 1: accept by lvalue reference
using CallbackType = std::function&lt;void(std::string&amp;)&gt;;
callback(message);

// Way 2: accept by rvalue reference
using CallbackType = std::function&lt;void(std::string&amp;&amp;)&gt;;
callback(std::move(message));

// Way 3: accept by const lvalue reference
using CallbackType = std::function&lt;void(const std::string&amp;)&gt;;
callback(message);

// Way 4: accept by lvalue
using CallbackType = std::function&lt;void(std::string)&gt;;
callback(message); // copy
callback(std::move(message)); // move
</code></pre>

<p>Way 1 seems to be the fastest (function can do string processing with the original string, avoiding any copy or move) but looks a bit confusing (people may wonder if they need to change this parameter).</p>

<p>Way 3 seems to be the most widely used way but is the slowest as the function will have to make a copy of passed string before processing.</p>

<p>Way 2 is probably in the middle by performance.</p>

<p><strong>UPDATE:</strong> Based on answers, added way 4 (caller can decide whether to copy or move).</p>