定义于头文件
<type_traits>
|
||
template< class T >
struct add_cv; |
(1) | (C++11 起) |
template< class T >
struct add_const; |
(2) | (C++11 起) |
template< class T >
struct add_volatile; |
(3) | (C++11 起) |
提供同 T
的成员 typedef type
,除了它拥有添加的 cv 限定符(除非 T
是函数、引用或已拥有 cv 限定符)
1) 添加 const 和 volatile
2) 添加 const
3) 添加 volatile
目录 |
名称 | 定义 |
type
|
带 cv 限定符的类型 T
|
template< class T >
using add_cv_t = typename add_cv<T>::type; |
(C++14 起) | |
template< class T >
using add_const_t = typename add_const<T>::type; |
(C++14 起) | |
template< class T >
using add_volatile_t = typename add_volatile<T>::type; |
(C++14 起) | |
template< class T > struct add_cv { typedef const volatile T type; }; template< class T> struct add_const { typedef const T type; }; template< class T> struct add_volatile { typedef volatile T type; }; |
输出:
Non-cv Const
(C++11)
|
检查类型是否为 const 限定 (类模板) |
(C++11)
|
检查类型是否为 volatile 限定 (类模板) |
(C++11)
(C++11) (C++11) |
从给定类型移除 const 或/与 volatile 限定符 (类模板) |
(C++17)
|
获得到其参数的 const 引用 (函数模板) |