std::add_lvalue_reference,std::add_rvalue_reference (3) - Linux Manuals
std::add_lvalue_reference,std::add_rvalue_reference: std::add_lvalue_reference,std::add_rvalue_reference
NAME
std::add_lvalue_reference,std::add_rvalue_reference - std::add_lvalue_reference,std::add_rvalue_reference
Synopsis
Defined in header <type_traits>
template< class T > (1) (since C++11)
struct add_lvalue_reference;
template< class T > (2) (since C++11)
struct add_rvalue_reference;
Creates a lvalue or rvalue reference type of T.
1) 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&. If T is an rvalue reference to some type U, then type is U&. Otherwise, type is T.
2) 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.
Member types
Name Definition
type reference to T, or T if not allowed
Helper types
template< class T > (since C++14)
using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;
template< class T > (since C++14)
using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;
Notes
These type transformations honor reference collapse rules:
std::add_lvalue_reference<T&>::type is T&
std::add_lvalue_reference<T&&>::type is T&
std::add_rvalue_reference<T&>::type is T&
std::add_rvalue_reference<T&&>::type is T&&
Possible implementation
Example
// Run this code
Output:
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
LWG_2101 C++11 These transformation traits were required Produce cv-/ref-qualified function types themselves.
See also
is_reference checks if a type is either a lvalue reference or rvalue reference
(C++11)
remove_reference removes a reference from the given type
(C++11)
remove_cvref combines std::remove_cv and std::remove_reference
(C++20)