Namespaces
Variants
Views
Actions

std::unwrap_reference, std::unwrap_ref_decay

From cppreference.com
< cpp‎ | utility‎ | functional
 
 
 
Function objects
Function wrappers
(C++11)
(C++11)
Partial function application
(C++20)
(C++11)
Function invocation
(C++17)
Identity function object
(C++20)
Reference wrappers
(C++11)(C++11)
unwrap_referenceunwrap_ref_decay
(C++20)(C++20)
Operator wrappers
Negators
(C++17)
Searchers
Constrained comparators
Old binders and adaptors
(until C++17)
(until C++17)
(until C++17)
(until C++17)
(until C++17)(until C++17)(until C++17)(until C++17)
(until C++20)
(until C++20)
(until C++17)(until C++17)
(until C++17)(until C++17)

(until C++17)
(until C++17)(until C++17)(until C++17)(until C++17)
(until C++20)
(until C++20)
 
Defined in header <functional>
template< class T >
struct unwrap_reference;
(1) (since C++20)
template< class T >
struct unwrap_ref_decay;
(2) (since C++20)
1) If T is std::reference_wrapper<U> for some type U, provides a member typedef type that names U&; otherwise, provides a member typedef type that names T.
2) If T is std::reference_wrapper<U> for some type U, ignoring cv-qualification and referenceness, provides a member typedef type that names U&; otherwise, provides a member typedef type that names std::decay_t<T>.

Contents

[edit] Member types

Name Definition
type

1) U& if T is std::reference_wrapper<U>; T otherwise

2) U& if std::decay_t<T> is std::reference_wrapper<U>; std::decay_t<T> otherwise

[edit] Helper types

template<class T>
using unwrap_reference_t = typename unwrap_reference<T>::type;
(1) (since C++20)
template<class T>
using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type;
(2) (since C++20)

[edit] Possible implementation

template <class T>
struct unwrap_reference { using type = T; };
template <class U>
struct unwrap_reference<std::reference_wrapper<U>> { using type = U&; };
 
template< class T >
struct unwrap_ref_decay : std::unwrap_reference<std::decay_t<T>> {};

[edit] Notes

std::unwrap_ref_decay performs the same transformation as used by std::make_pair and std::make_tuple.

[edit] Example

[edit] See also

CopyConstructible and CopyAssignable reference wrapper
(class template) [edit]
creates a pair object of type, defined by the argument types
(function template) [edit]
creates a tuple object of the type defined by the argument types
(function template) [edit]