Reference types and literals
I looked in the standard for a reference type definition, but I couldn't find one. The naive interpretation of a reference type as a type of objects such as int &
fails because according to the [basic.types] 10.3 standard:
Type - the type of the literal, if it is: [...] a reference type
But the following static assert does not compile (in MSVC2015RC):
static_assert( ::std::is_literal_type< ::std::wstring & >::value, "Nope" );
What is the definition of a reference type?
source to share
The C ++ 11 standard defines references in section 8.3.3 [dcl.ref]:
1 In an ad
T D
where itD
has one of the forms
& attribute-specifier-seqopt D1 && attribute-specifier-seqopt D1
and the type of the identifier in the declaration
T D1
is "name-type-declarator-type T", then the type of the identifier isD
"reference to type-declarator-type-list forT
". The optional attribute-specifier-seq is of the reference type. Cv-qualified references are poorly formed unless cv-qualifiers are entered using a typedef (7.1.3) or a template-type argument (14.3), in which case the cv-qualifiers are ignored. [...]2 A reference type that is declared using and is called an lvalue, and a reference type that is declared using && & is called an rvalue reference. Lvalue references and rvalue references are different types. Except where explicitly stated, they are semantically equivalent and are commonly referred to as references.
Simply put, reference types are types that are declared as references to other types. However, there is much more to be said about your behavior.
source to share