GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::decay(3) C++ Standard Libary std::decay(3)

std::decay - std::decay


Defined in header <type_traits>
template< class T > (since C++11)
struct decay;


Applies lvalue-to-rvalue, array-to-pointer, and function-to-pointer implicit
conversions to the type T, removes cv-qualifiers, and defines the resulting type as
the member typedef type. Formally:


* If T names the type "array of U" or "reference to array of U", the member
typedef type is U*.


* Otherwise, if T is a function type F or a reference thereto, the member typedef
type is std::add_pointer<F>::type.


* Otherwise, the member typedef type is
std::remove_cv<std::remove_reference<T>::type>::type.


These conversions model the type conversion applied to all function arguments when
passed by value.


The behavior of a program that adds specializations for decay is undefined.


Name Definition
type the result of applying the decay type conversions to T


template< class T > (since C++14)
using decay_t = typename decay<T>::type;


template< class T >
struct decay {
private:
typedef typename std::remove_reference<T>::type U;
public:
typedef typename std::conditional<
std::is_array<U>::value,
typename std::remove_extent<U>::type*,
typename std::conditional<
std::is_function<U>::value,
typename std::add_pointer<U>::type,
typename std::remove_cv<U>::type
>::type
>::type type;
};

// Run this code


#include <type_traits>


template <typename T, typename U>
struct decay_equiv :
std::is_same<typename std::decay<T>::type, U>::type
{};
template <typename T, typename U>
constexpr bool is_decay_equ = decay_equiv<T, U>::value;


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


remove_cvref combines std::remove_cv and std::remove_reference
(C++20) (class template)
implicit conversion array-to-pointer, function-to-pointer, lvalue-to-rvalue
conversions

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.