std::meta::decay
From cppreference.com
| Defined in header <meta>
|
||
consteval std::meta::info decay( std::meta::info r );
|
(since C++26) | |
Performs the type conversions equivalent to the ones performed when passing function arguments by value.
Let T be the type represented by r. Then:
- If
Tis âarray of Uâ or reference to it, equivalent toreturn std::meta::dealias(^^U*);. - Otherwise, if
Tis a function typeFor reference to one, equivalent toreturn std::meta::dealias(^^std::add_pointer_t<F>);. - Otherwise, equivalent to
return std::meta::dealias(^^std::remove_cvref_t<T>);.
In any case, the call to this function is equivalent to return std::meta::dealias(std::decay_t<T>).
Parameters
| r | - | a reflection value |
Return value
A reflection of âdecayedâ underlying type T.
Exceptions
Throws std::meta::exception if r does not represent a type or type alias.
Example
Run this code
#include <meta>
static_assert
(""
&& (decay(^^int) == ^^int)
&& (decay(^^int) != ^^float)
&& (decay(^^int&) == ^^int)
&& (decay(^^int&&) == ^^int)
&& (decay(^^const int&) == ^^int)
&& (decay(^^int[2]) == ^^int*)
&& (decay(^^int[4][2]) != ^^int*)
&& (decay(^^int[4][2]) != ^^int**)
&& (decay(^^int[4][2]) == ^^int(*)[2])
&& (decay(^^int(int)) == ^^int(*)(int))
);
int main() {}
See also
| Implicit conversions | array-to-pointer, function-to-pointer, lvalue-to-rvalue conversions |
(C++26) |
combines meta::remove_cv and meta::remove_reference (function) |
(C++26)(C++26)(C++26) |
removes const and/or volatile qualifiers from reflected type (function) |
(C++26) |
removes a reference from reflected type (function) |
(C++11) |
applies type transformations as when passing a function argument by value (class template) |