定义于头文件
<type_traits>
|
||
template< class T >
struct remove_cvref; |
(C++20 起) | |
若类型 T
为引用类型,则提供成员 type
,它是移除了其最顶层 cv 限定符的 T
所引用的类型。否则 type
为移除最顶层 cv 限定符的 T
。
目录 |
名称 | 定义 |
type
|
T 所引用的类型,或若 T 不是引用则为其自身,移除顶层 cv 限定符
|
template< class T >
using remove_cvref_t = typename remove_cvref<T>::type; |
(C++20 起) | |
template< class T > struct remove_cvref { typedef std::remove_cv_t<std::remove_reference_t<T>> type; }; |
#include <iostream> #include <type_traits> int main() { std::cout << std::boolalpha << std::is_same_v<std::remove_cvref_t<int>, int> << '\n' << std::is_same_v<std::remove_cvref_t<int&>, int> << '\n' << std::is_same_v<std::remove_cvref_t<int&&>, int> << '\n' << std::is_same_v<std::remove_cvref_t<const int&>, int> << '\n' << std::is_same_v<std::remove_cvref_t<const int[2]>, int[2]> << '\n' << std::is_same_v<std::remove_cvref_t<const int(&)[2]>, int[2]> << '\n' << std::is_same_v<std::remove_cvref_t<int(int)>, int(int)> << '\n'; }
输出:
true true true true true true true
(C++11)
(C++11) (C++11) |
从给定类型移除 const 或/与 volatile 限定符 (类模板) |
(C++11)
|
从给定类型移除引用 (类模板) |
(C++11)
|
将类型变换成以值形式传递给函数时使用的类型 (类模板) |