c ++:'std :: is_fundamental'的替代品?

Sub*_*way 5 c++ type-traits c++11

在模板类中的函数中,我试图区分原始类型和其他类型.

在c ++ 11中,您可以:

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

如果我错了,请纠正我,这不仅仅是在c ++ 11中.

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

djf*_*djf 8

您可以在C++ 03中使用Boost的类型特征,如下所示:

#include  <boost/type_traits/is_fundamental.hpp>

...

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

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