获取模板类型的基类型(删除const/reference/etc.)

edA*_*a-y 11 c++ templates c++11

是否有类型特征模板,它返回给定类型的基本类型.通过碱型我的意思是与所有值调节剂,const的,易失性类型等剥离.例如,使用假设特征函数:

base<int>::type == int
base<int const>::type == int
base<int&>::type == int
Run Code Online (Sandbox Code Playgroud)

我知道remove_const并且remove_reference目前正在组合使用它们.我想知道是否存在这样的特征,或许是否有一个正确的名称我所指的是什么?

And*_*owl 14

我会在probaby中定义一个类型别名,例如:

template<typename T>
using base_type = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
Run Code Online (Sandbox Code Playgroud)

请注意,这里 R. Martinho Fernandes提出了Unqualified这种类型别名的名称.

标准型特点std::decay,在另一方面做同样的上面数组和函数类型更多的东西,这可能是也可能不是你想要的是.


And*_*zej 5

尝试一下std::decay。它模仿了当您按值将参数传递给函数时会发生的情况:剥离顶级cv限定词,引用,将数组转换为指针并将函数转换为函数指针。

问候,&rzej