Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Good point. I guess there are two things to look at: 1) as you pointed out the non-class rvalue thingsy and 2) how overload resolution works:</p> <blockquote> <p>The selection criteria for the best function are the number of arguments, how well the arguments match the parameter-type-list of the candidate function, [...]</p> </blockquote> <p>I haven't seen anything in the standard that tells me non-class rvalues are treated specially during overload resolution.</p> <p>Your question is covered in the draft of the standard I have though (N-4411) somewhat:</p> <p>What does come into play is however a parallel reading of reference binding, implicit conversion sequences, references, and overload resolution in general:</p> <p><strong>13.3.3.1.4 Reference binding</strong></p> <blockquote> <p>2 When a parameter of reference type is not bound directly to an argument expression, the conversion sequence is the one required to convert the argument expression to the underlying type of the reference according to 13.3.3.1.</p> </blockquote> <p>and</p> <p><strong>13.3.3.2 Ranking implicit conversion sequences</strong></p> <blockquote> <p>3 Two implicit conversion sequences of the same form are indistinguishable conversion sequences unless one of the following rules applies:</p> <p>— Standard conversion sequence S1 is a better conversion sequence than standard<br> conversion sequence S2 if</p> <p>— S1 and S2 are reference bindings (8.5.3) and neither refers to an implicit object parameter of a nonstatic member function declared without a ref-qualifier, and either S1 binds an lvalue reference to an lvalue and S2 binds an rvalue reference or S1 binds an rvalue reference to an rvalue and S2 binds an lvalue reference.</p> <p>[ Example:</p> </blockquote> <pre><code>int i; int f(); int g(const int&amp;); int g(const int&amp;&amp;); int j = g(i); // calls g(const int&amp;) int k = g(f()); // calls g(const int&amp;&amp;) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload