获取模板类型的基本类型(删除const / reference / etc。) [英] Get base type of a template type (remove const/reference/etc.)

查看:51
本文介绍了获取模板类型的基本类型(删除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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆