On this page
std::decay
Defined in header <type_traits> |
||
---|---|---|
|
(since C++11) |
Performs the type conversions equivalent to the ones performed when passing function arguments by value. Formally:
- If
T
is "array ofU
" or reference to it, the member typedeftype
isU*
. - Otherwise, if
T
is a function typeF
or reference to one, the member typedeftype
is std::add_pointer<F>::type. - Otherwise, the member typedef
type
is std::remove_cv<std::remove_reference<T>::type>::type.
The behavior of a program that adds specializations for std::decay
is undefined.
Member types
Name | Definition |
---|---|
type |
the result of applying the decay type conversions to T |
Helper types
|
(since C++14) |
Possible implementation
|
Example
#include <type_traits>
template<typename T, typename U>
constexpr bool is_decay_equ = std::is_same_v<std::decay_t<T>, U>;
int main()
{
static_assert
(
is_decay_equ<int, int> &&
! is_decay_equ<int, float> &&
is_decay_equ<int&, int> &&
is_decay_equ<int&&, int> &&
is_decay_equ<const int&, int> &&
is_decay_equ<int[2], int*> &&
! is_decay_equ<int[4][2], int*> &&
! is_decay_equ<int[4][2], int**> &&
is_decay_equ<int[4][2], int(*)[2]> &&
is_decay_equ<int(int), int(*)(int)>
);
}
See also
(C++20)
|
combines std::remove_cv and std::remove_reference (class template) |
implicit conversion |
array-to-pointer, function-to-pointer, lvalue-to-rvalue conversions |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/types/decay