| |
|
|
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>>;
};
注解
示例
#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)>);
}
参阅