I know that if a variable or parameter is declared to have type T&&
for some deduced type T
, that variable or parameter is widely called a universal reference.
The term universal reference was introduced by Scott Meyers in his original talk “Universal References in C++11”. However, I wonder what's the official/standard term for universal references.
Overview
It is known that since C++11, a parameter of type
T&&
is called an rvalue reference [ISO/IEC 14882:2011 §8.3.2/p2 References [dcl.ref] ]. That is, unlessT
is a template parameter type orauto
or atypedef
for some lvalue reference type.Although technically
T&&
in the examples above is still an rvalue reference, its behaviour differs significantly from a regular one.Naturally, you would ask "why this special case doesn't have a special syntax". The answer is that the
&&
syntax was intentionally overloaded for this special construct by the C++ committee. However, they missed to name this special case.In the absence of a distinct name for this particular construct, Scott Meyers coined the widely known term/name universal references.
The committee however, decided that this name is not proper for a number of reasons. As such, the proposal N4164 made by Herb Sutter, Bjarne Stroustrup and Gabriel Dos Reis proposed to change the name to Forwarding References.
The name Forwarding References had the most support in informal discussions among committee members, including the authors of the proposal mentioned earlier. Interestingly enough, it was Scott Meyers himself that introduced that term in his original “Universal References” talk. However, later he decided to go along with the name universal references. For this decision played role the fact that at the time he didn't think that the term forwarding references included also the
auto&&
case.Why not universal references?
According to the proposal the term Universal references although is a reasonable name with an obvious meaning, it happens to be wrong in several aspects.
A universal reference must mean the following:
Obviously this is not the case nor is the appropriate use of this construct. Furthermore, this name would encourage many people to consider that something having such a name is meant to be used "universally". Something that the committee considered it a bad thing.
Moreover, "universal references" aren’t even really references per se, but rather a set of rules for using references in a particular way in a particular context with some language support for that use, and that use is forwarding.
Why
auto&&
is Also Considered a Forwarding caseauto&&
is also considered a forward case since it follows the reference collapsing rules. For example in:[](auto&& x){ … }
for
-ranged loop of the form,for(auto &&i : v) { ... }
auto&&
local variables are for forwarding.Standard Wordings for Forwarding References
The term forwarding references is mentioned in the draft standard N4527 in the following places:
§14.8.2.1/ Deducing template arguments from a function call [temp.deduct.call] (Emphasis Mine):
§14.8.2.5/p10 Deducing template arguments from a type [temp.deduct.type]: