std::remove_cvref

来自cppreference.com
< cpp‎ | types
 
 
元编程库
类型特征
类型类别
(C++11)
(C++11)(DR*)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11) 
类型属性
(C++11)
(C++11)
(C++14)
(C++11)(C++26 弃用)
(C++11)(C++20 前*)
(C++11)(C++20 弃用)
(C++11)
类型特征常量
元函数
(C++17)
受支持操作
关系与属性查询
类型修改
类型变换
(C++11)(C++23 弃用)
(C++11)(C++23 弃用)
(C++11)
remove_cvref
(C++20)
(C++11)(C++20 前*)(C++17)

编译时有理数算术
编译时整数序列
 
在标头 <type_traits> 定义
template<class T >
struct remove_cvref;
(C++20 起)

若类型 T 为引用类型,则提供成员 type,它是移除了最顶层 cv 限定符的 T 所引用的类型。否则 type 为移除最顶层 cv 限定符的 T

如果程序添加了 std::remove_cvref 的特化,那么行为未定义。

目录

[编辑]成员类型

名称 定义
typeT 所引用的类型,或若 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_cvref201711L(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)>);}

[编辑]参阅

从给定类型移除 const 和/或 volatile 限定符
(类模板)[编辑]
从给定类型移除引用
(类模板)[编辑]
(C++11)
应用当按值传递实参给函数时所进行的类型变换
(类模板)[编辑]
close