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&);
}
}
