Why duplicate code is needed with const reference arguments? : <p>In this <a href="http://www.stlport.org/resources/StepanovUSA.html">interview</a> Stepanov shows how to implement generic <code>max</code> function in C++. </p>

<blockquote>
  <p>Try to implement a simple thing in the object oriented way, say, max.
  I do not know how it can be done. Using generic programming I can
  write:</p>

<pre><code>template &lt;class StrictWeakOrdered&gt;
inline StrictWeakOrdered&amp; max(StrictWeakOrdered&amp; x,
StrictWeakOrdered&amp; y) {
return x &lt; y ? y : x;
}

and
template &lt;class StrictWeakOrdered&gt;
inline const StrictWeakOrdered&amp; max(const StrictWeakOrdered&amp; x,
const StrictWeakOrdered&amp; y) {
return x &lt; y ? y : x;
}
</code></pre>
  
  <p>(you do need both &amp; and const &amp;).</p>
</blockquote>

<p>Why is there need to write the code twice? Is this needed to aid compiler for optimization or a convention to reduce bugs? Is <code>max</code> a special case where body of a <code>const</code> version is identical? </p>

<p>How many valid <code>const</code> and non-<code>const</code> permutations a function of N arguments should have to define a complete API?</p>
