Spec-Zone.ru › C++

std::meta::decay

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

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/meta/decay

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API