Why does adding const turn a forwarding reference into an rvalue reference?

The official name is not universal reference, but forwarding reference. The Standard states that only rvalue references to cv-unqualified template parameters fall in this category: 14.8.2.1 Deducing template arguments from a function call [temp.deduct.call] 3 If P is a cv-qualified type, the top level cv-qualifiers of P’s type are ignored for type deduction. If P … Read more

Why do forwarding references have the same syntax as rvalue references?

I think it happened the other way around. The initial idea was to introduce rvalue-references into the language, meaning that “the code providing the double-ampersand reference does not care about what will happen to the referred-to object”. This permits move semantics. This is nice. Now. The standard forbids constructing a reference to a reference, but … Read more

How does std::forward work, especially when passing lvalue/rvalue references? [duplicate]

I think the explanation of std::forward as static_cast<T&&> is confusing. Our intuition for a cast is that it converts a type to some other type — in this case it would be a conversion to an rvalue reference. It’s not! So we are explaining one mysterious thing using another mysterious thing. This particular cast is … Read more

Is there a difference between universal references and forwarding references?

Do they mean the same thing? Universal reference was a term Scott Meyers coined to describe the concept of taking an rvalue reference to a cv-unqualified template parameter, which can then be deduced as either a value or an lvalue reference. At the time the C++ standard didn’t have a special term for this, which … Read more

What does auto&& tell us?

By using auto&& var = <initializer> you are saying: I will accept any initializer regardless of whether it is an lvalue or rvalue expression and I will preserve its constness. This is typically used for forwarding (usually with T&&). The reason this works is because a “universal reference”, auto&& or T&&, will bind to anything. … Read more