std::remove_cvref
来自cppreference.com
在标头 <type_traits> 定义 | ||
template<class T > struct remove_cvref; | (C++20 起) | |
若类型 T
为引用类型,则提供成员 type
,它是移除了最顶层 cv 限定符的 T
所引用的类型。否则 type
为移除最顶层 cv 限定符的 T
。
如果程序添加了 std::remove_cvref
的特化,那么行为未定义。
目录 |
[编辑]成员类型
名称 | 定义 |
type | T 所引用的类型,或若 T 不是引用则为其自身,移除顶层 cv 限定符 |
[编辑]辅助类型
template<class T > using remove_cvref_t = remove_cvref<T>::type; | (C++20 起) | |
[编辑]可能的实现
template<class T>struct remove_cvref {using type =std::remove_cv_t<std::remove_reference_t<T>>;}; |
[编辑]注解
功能特性测试宏 | 值 | 标准 | 功能特性 |
---|---|---|---|
__cpp_lib_remove_cvref | 201711L | (C++20) | std::remove_cvref |
[编辑]示例
运行此代码
#include <type_traits> int main(){ static_assert(std::is_same_v<std::remove_cvref_t<int>, int>); static_assert(std::is_same_v<std::remove_cvref_t<int&>, int>); static_assert(std::is_same_v<std::remove_cvref_t<int&&>, int>); static_assert(std::is_same_v<std::remove_cvref_t<constint&>, int>); static_assert(std::is_same_v<std::remove_cvref_t<constint[2]>, int[2]>); static_assert(std::is_same_v<std::remove_cvref_t<constint(&)[2]>, int[2]>); static_assert(std::is_same_v<std::remove_cvref_t<int(int)>, int(int)>);}
[编辑]参阅
(C++11)(C++11)(C++11) | 从给定类型移除 const 和/或 volatile 限定符 (类模板) |
(C++11) | 从给定类型移除引用 (类模板) |
(C++11) | 应用当按值传递实参给函数时所进行的类型变换 (类模板) |