c++: 'std::is_fundamental' 的替代方案?

标签 c++ c++11 typetraits

在模板类中的函数中,我试图区分基本类型和其他类型。

在 C++ 11 中你可以这样做:

if(std::is_fundamental<T>::value)
{
    // Treat it as a primitive
}
else
{
    //Treat it otherwise
}

如果我错了,请纠正我,这不仅在 C++ 11 中。

在早期版本的 c++ 中是否有替代方案?

最佳答案

你可以使用 Boost's type traits在 C++03 中是这样的:

#include  <boost/type_traits/is_fundamental.hpp>

...

if(boost::is_fundamental<T>::value)
{
    // Treat it as a primitive
}
else
{
    //Treat it otherwise
}

我想这也适用于 C++98。

关于c++: 'std::is_fundamental' 的替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16807414/

相关文章:

c++ - 计算平均值最大值和最小值 C++

c++ - 无法在列表 vector 中使用列表

c++ - 如何在 Redhat Enterprise 上安装 C++11 C++0x 头文件

c++ - 为什么不允许通过 decltype(lamda) 定义对象,我该如何改进它?

C++11 内存池类 - 从 void* 进行 static_casting 的解决方法?

c++ - libstdc++对std::declval的实现问题

c++ - Qt——QWidget到底是什么

c++ - 从 unordered_multiset 读取会导致崩溃

c++ - 是否可以根据分配对象的类型特征覆盖全局 new 运算符?

c++ - 为什么 std::void_t 在这种情况下不起作用?