std::decay
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    |   定义于头文件  <type_traits>
  | 
||
|   template< class T > struct decay;  | 
(C++11 起) | |
对类型 T 应用左值到右值、数组到指针及函数到指针隐式转换,移除 cv 限定符,并定义结果类型为成员 typedef type 。正式而言:
-  若
T指名“U的数组”或“到U的数组的引用”类型,则成员 typedeftype为 U* 。 
-  否则,若 
T为函数类型F或到它的引用,则成员 typedeftype为std::add_pointer<F>::type 。 
-  否则,成员 typedef 
type为 std::remove_cv<std::remove_reference<T>::type>::type 。 
这些转换模仿在以值传递时,应用到所有函数参数的类型转换。
添加 decay 的特化的程序行为未定义。
成员类型
| 名称 | 定义 | 
  type
 | 
 应用退化类型转换到 T 的结果
 | 
辅助类型
|   template< class T > using decay_t = typename decay<T>::type;  | 
(C++14 起) | |
可能的实现
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; };  | 
示例
运行此代码
#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'; }
输出:
true true true true true true
参阅
|    (C++20)  | 
  将 std::remove_cv 与 std::remove_reference 结合  (类模板)  | 
| 隐式转换 | 数组到指针、函数到指针、左值到右值转换 |