C++ Templates - The Complete Guide, in §C.1, reads
- Overload resolution is performed to find the best candidate. If there is one, it is selected; otherwise, the call is ambiguous.
Then, in §C.2, ranks the possible matches (of a given argument with the corresponding parameter of a viable candidate) like this (my emphasis):
- Perfect match. The parametere has the type of the expression, or it has a type that is a reference to the type of the expression (possible with added
const
and/orvolatile
qualifiers).- Match with minor adjustments. This includes, for example, the decay of an array variable to a pointer to its first element or the addition of
const
to match an argument of typeint**
to a parameter of typeint const* const*
.- Match with promotion. …
- Match with standard conversions only. …
- Match with user-defined conversion. …
- Match with ellipsis (
...
). …
Now, since top level const
of by-value parameters are not part of the signature of a function, I think that the part in parenthesis in the first point refers to the case that the parameter is a reference to the type of the expression. If my interpretation is correct, that means that a T const&
parameter is a perfect match for an argument of type T
.
After all, in §C.2.2, I see that confirmed:
For an argument of type
X
, there are four common parameter types that constitute a perfect match:X
,X&
,X const&
, andX&&
(X const&&
is also an exact match, …)
And then the book goes on with some example that show how the category value of the argument determines what overload is selected.
But if all of X
, X&
, X const&
, X&&
, and X const&&
are perfect matches, then when is one of them preferred based on the value category of the argument?
Isn't that part of overload resolution? If so, why the value category is not mentioned at all in the points above?