首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::decay

Defined in header <type_traits>

template< class T > struct decay;

(since C++11)

将lvalue到rvalue、数组到指针以及函数到指针的隐式转换应用于类型。T,移除cv-限定符,并将结果类型定义为type.正式:

  • 如果T命名类型“数组U“或”引用U“,成员类型ftypeU*...
  • 否则,如果T是函数类型F或对该成员的引用,typestd::add_pointer<F>::type...
  • 否则,则为typestd::remove_cv<std::remove_reference<T>::type>::type...

这些转换建立了类型转换的模型,当通过值传递时,类型转换应用于所有函数参数。

成员类型

Name

Definition

type

the result of applying the decay type conversions to T

帮助者类型

template< class T > using decay_t = typename decay<T>::type;

(since C++14)

可能的实施

模板<class T>结构衰变{私有:tyduif类型名称STD::Remove[医]参照系<T>::U类型;public:tyduif type Name std::条件<std::is[医]列阵<U>*值,类型名称STD::Remove[医]程度<U>*类型%2A,类型名称std::条件<std::is[医]功能<U>*value,type name std:::Add[医]指针<U>*输入,类型名称STD::删除[医]CV<U>*类型>:类型>:类型;};

*。

二次

代码语言:javascript
复制
#include <iostream>
#include <type_traits>
 
template <typename T, typename U>
struct decay_equiv : 
    std::is_same<typename std::decay<T>::type, U>::type 
{};
 
int main()
{
    std::cout << std::boolalpha
              << decay_equiv<int, int>::value << '\n'
              << decay_equiv<int&, int>::value << '\n'
              << decay_equiv<int&&, int>::value << '\n'
              << decay_equiv<const int&, int>::value << '\n'
              << decay_equiv<int[2], int*>::value << '\n'
              << decay_equiv<int(int), int(*)(int)>::value << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
true
true
true
true
true
true

二次

另见

implicit conversion

array-to-pointer, function-to-pointer, lvalue-to-rvalue conversions

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券