创建is_primitive或is_inheritable模板

Sue*_*ode 1 c++ templates std c++11

我想创建一个模板来检查类类型是否是原始类型(int,char,float,float***,ect ...).这样做的原因是为了防止另一个模板尝试扩展原语并导致编译时错误.到目前为止,我有以下几点:

#include <typeinfo>
template<typename T>
struct is_primitive{
   const static bool value=std::is_fundamental<T>::value;
};
Run Code Online (Sandbox Code Playgroud)

显然,这只是转发is_fundamental的结果.我想添加remove_pointer,remove_reference,ect ...来删除输入类的所有额外修饰符. 使T尽可能裸露所需的所有移除是什么?

或者,像下面这样的解决方案也同样出色:

template<typename T>
struct is_inheritable{
   const static bool value=???;
};
Run Code Online (Sandbox Code Playgroud)

但我很确定不可继承的类集等于原始类的集合.

How*_*ant 5

这听起来像你想要的std::is_class<T>.一个人只能继承类类型.这是一个描述C++ 11类型分类特征的图表:这里http://howardhinnant.github.io/TypeHiearchy.pdf

http://howardhinnant.github.io/TypeHiearchy.pdf