Const applies to the "universal link" parameter

I came across Scott Myers article on universal links, link .

From what I understood the universal link, that is, some type T&&may mean the type rvalue or lvalue in different contexts.

For example:

template<typename T>
void f(T&& param);               // deduced parameter type ⇒ type deduction;
                                 // && ≡ universal reference

In the above example, depending on the template parameter, it T&&can be either lvalue or rvalue, i.e. it depends on what we callf

int x = 10;
f(x); // T&& is lvalue (reference)
f(10); // T&& is rvalue

However, according to Scott, if we apply constto the above example, the type is T&&always rvalue:

template<typename T>
void f(const T&& param);               // "&&" means rvalue reference

Quote from the article:

Even a simple addition to the const specifier is enough to disable the interpretation of & & as a universal reference:

: const "" rvalue?

, , :

template<typename T>
void f(const T&& param);               // "&&" means rvalue reference

int x = 10;
f(x); // T&& is lvalue (reference) // how does 'x' suddenly become an rvalue because of const?
f(10); // T&& is rvalue // OK
+1

All Articles