cppreference.com about std::add_lvalue_reference
/std::add_rvalue_reference
:
If T is an object type or a function type that has no cv- or ref- qualifier, provides a member typedef type which is T&&, otherwise type is T.
Does it mean that if T is const or volatile than T is not converted to reference? If no, then what does it mean "has no cv-qualifier".
Does it mean that if T is const or volatile than T is not converted to reference?
Yes, but only if it is a function.
The quote from cppreference can be a little confusing. cppreference has
If T is an object type or a function type that has no cv- or ref- qualifier, provides a member typedef type which is T&&, otherwise type is T.
which can make you believe the cv-qualifer part applies to both objects and functions, but this is not the case. The actual text from the standard is
an object type, a function type that does not have cv-qualifiers or a ref-qualifier, or a reference type
so any object type and any function without a cv-qualifier and ref-qualifier will yield a reference. references or functions with a cv-qualifier and/or ref-qualifier will yield T
When you see cv-qualifier that means const and or volatile qualifier, i.e. it is a const and or volatile object or const or volatile qualified function. ref-qualifier that means reference qualifier, i.e. the function can only be called on an lvalue or rvalue: void foo() &
or void foo() &&
.
It's trying to say that the result is respectively T&
or T&&
if either:
T
is an object type, orT
is a function type that does not have any cv-qualifiers and does not have a ref-qualifier.The restriction "has no cv- or ref-qualifier" does not apply to object types. It applies to function types because if a function type has a cv- or ref-qualifier, then it is not possible to create the referenced type. See Abominable Function Types for some discussion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With