template< class T >
struct add_lvalue_reference;
template< class T >
struct add_rvalue_reference;
Creates an lvalue or rvalue reference type of T
.
type
T
is a referenceable type T
is not a referenceable type (1) T&
[1] T
(2) T&&
[2]
T&
, which is not an rvalue reference type.If the program adds specializations for any of the templates described on this page, the behavior is undefined.
[edit] Nested types Name Definitiontype
determined as above [edit] Helper types
template< class T >
using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;
template< class T >
using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;
The major difference to directly using T&
or T&&
is that T
can be a non-referenceable type. For example, std::add_lvalue_reference<void>::type is void, while void& leads to a compilation error.
namespace detail { template<class T> struct type_identity { using type = T; }; // or use std::type_identity (since C++20) template<class T> // Note that âcv void&â is a substitution failure auto try_add_lvalue_reference(int) -> type_identity<T&>; template<class T> // Handle T = cv void case auto try_add_lvalue_reference(...) -> type_identity<T>; template<class T> auto try_add_rvalue_reference(int) -> type_identity<T&&>; template<class T> auto try_add_rvalue_reference(...) -> type_identity<T>; } // namespace detail template<class T> struct add_lvalue_reference : decltype(detail::try_add_lvalue_reference<T>(0)) {}; template<class T> struct add_rvalue_reference : decltype(detail::try_add_rvalue_reference<T>(0)) {};[edit] Example [edit] 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 the program was ill-formed ifT
is a function type with cv or ref the type produced is T
in this case [edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4