Namespaces
Variants

std::meta::decay

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Type properties
Type property queries
 
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 T is “array of U” or reference to it, equivalent to return std::meta::dealias(^^U*);.
  • Otherwise, if T is a function type F or reference to one, equivalent to return 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

#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
combines meta::remove_cv and meta::remove_reference
(function) [edit]
removes const and/or volatile qualifiers from reflected type
(function) [edit]
removes a reference from reflected type
(function) [edit]
(C++11)
applies type transformations as when passing a function argument by value
(class template) [edit]