获取模板类型的基本类型(删除const / reference / etc。) [英] Get base type of a template type (remove const/reference/etc.)
问题描述
是否存在类型特征模板,该模板返回给定类型的基本类型。 基本类型是指去除所有值修饰符,const,volatile等的类型。例如,使用假设特征函数:
Is there a type traits template which returns the base type of a given type. By base type I mean the type with all value modifiers, const, volatile, etc. stripped off. For example, using a hypothetical traits function:
base<int>::type == int
base<int const>::type == int
base<int&>::type == int
我知道 remove_const
和 remove_reference
,目前仅将它们组合使用。我想知道是否已经存在这样的特征,也许我所指的名称是否有合适的名称?
I'm aware of remove_const
and remove_reference
and am currently just using them in combination. I'm wondering if however there exists already such a trait and perhaps if there is a proper name to what I am referring?
推荐答案
我可能会定义类型别名,例如:
I would probaby define a type alias such as:
template<typename T>
using base_type = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
请注意,此处 R。 Martinho Fernandes 为这种类型别名建议使用名称不合格
。
Notice, that here R. Martinho Fernandes proposes the name Unqualified
for such a type alias.
标准类型特征 std :: decay
,在另一方面,对于数组和函数类型,它们的功能与上面的和相同。
这篇关于获取模板类型的基本类型(删除const / reference / etc。)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!