std::meta::unwrap_reference, std::meta::unwrap_ref_decay
From cppreference.com
| Defined in header <meta>
|
||
consteval std::meta::info unwrap_reference( std::meta::info r );
|
(1) | (since C++26) |
consteval std::meta::info unwrap_ref_decay( std::meta::info r );
|
(2) | (since C++26) |
Unwraps any std::reference_wrapper by changing std::reference_wrapper<U> to U&.
Let T be a type represented by r.
Equivalent to
return std::meta::dealias(^^std::unwrap_reference_t<T>);.2) If the decayed
T is a specialization of std::reference_wrapper, unwraps it; otherwise, T is decayed. Equivalent to
return std::meta::dealias(^^std::unwrap_ref_decay_t<T>);.Parameters
| r | - | a reflection value |
Return value
A reflection of:
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.Exceptions
Throws std::meta::exception if r does not represent a type or type alias.
Notes
std::unwrap_ref_decay performs the same transformation as used by std::make_pair and std::make_tuple.
Example
Run this code
#include <functional>
#include <meta>
static_assert
(
(unwrap_reference(^^int) == ^^int) &&
(unwrap_reference(^^const int) == ^^const int) &&
(unwrap_reference(^^int&) == ^^int&) &&
(unwrap_reference(^^int&&) == ^^int&&) &&
(unwrap_reference(^^int*) == ^^int*) &&
(unwrap_ref_decay(^^int) == ^^int) &&
(unwrap_ref_decay(^^const int) == ^^int) &&
(unwrap_ref_decay(^^const int&) == ^^int)
);
int main()
{
{
using T = std::reference_wrapper<int>;
constexpr auto X{unwrap_reference(^^T)};
static_assert(X == ^^int&);
}
{
using T = std::reference_wrapper<int&>;
constexpr auto X{unwrap_reference(^^T)};
static_assert(X == ^^int&);
}
{
using T = std::reference_wrapper<int&&>;
constexpr auto X{unwrap_ref_decay(^^T)};
static_assert(X == ^^int&);
}
}
See also
(C++26) |
applies type transformations as when passing a function argument by value (function) |
(C++11) |
CopyConstructible and CopyAssignable reference wrapper (class template) |
creates a pair object of type, determined by the argument types (function template) | |
(C++11) |
creates a tuple object of the type defined by the argument types (function template) |
(C++20)(C++20) |
get the reference type wrapped in std::reference_wrapper (class template) |