Best way of passing callback function parameters in C++ : <p>What is the best way of passing a <strong>callback function</strong> parameter in C++?</p>

<p>I thought of simply using templates, like this:</p>

<pre><code>template &lt;typename Function&gt;
void DoSomething(Function callback)
</code></pre>

<p>This is the way used e.g. in <a href="http://en.cppreference.com/w/cpp/algorithm/sort" rel="noreferrer"><code>std::sort</code></a> for the comparison function object.</p>

<p>What about passing using <strong><code>&amp;&amp;</code></strong>? E.g.:</p>

<pre><code>template &lt;typename Function&gt;
void DoSomething(Function&amp;&amp; callback)
</code></pre>

<p>What are the pros and cons of those two methods, and why does the STL uses the former e.g. in <code>std::sort</code>?</p>
