命名空间
变体
操作

std::remove_cvref

来自 cppreference.cn
< cpp‎ | 类型
 
 
元编程库
类型特性
类型类别
(C++11)
(C++11)(DR*)
(C++11)
(C++11)
(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++11)(C++11)
类型转换
(C++11)(C++23 中已弃用)
(C++11)(C++23 中已弃用)
(C++11)
remove_cvref
(C++20)
(C++11)(直到 C++20*)(C++17)

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

如果类型 T 是引用类型,则提供成员 typedef type,其为 T 所引用的类型,并去除了其最顶层的 cv 限定符。否则 typeT,并去除了其最顶层的 cv 限定符。

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

目录

[编辑] 成员类型

名称 定义
类型 如果 T 不是引用,则为 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<const int&>, int>);
    static_assert(std::is_same_v<std::remove_cvref_t<const int[2]>, int[2]>);
    static_assert(std::is_same_v<std::remove_cvref_t<const int(&)[2]>, int[2]>);
    static_assert(std::is_same_v<std::remove_cvref_t<int(int)>, int(int)>);
}

[编辑] 参阅

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