Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between std::is_integer and std::is_integral?

C++11 provides two type trait template classes: std::is_integer and std::is_integral. However, I cannot tell the differences between them.

What type, say T, can make std::is_integer<T>::value true and make std::is_integral<T>::value false?

like image 231
xmllmx Avatar asked Feb 03 '13 19:02

xmllmx


People also ask

What is Is_integral?

std::is_integralTrait class that identifies whether T is an integral type. It inherits from integral_constant as being either true_type or false_type, depending on whether T is an integral type: fundamental integral types. bool. char.

Is bool an integral type?

bool is a one bit integral type. There are many integral types -- int , long , long long , std::uint32_t .

What are C++ integral types?

The integral types are: char , signed char , unsigned char -8 bits. short int , signed short int , and unsigned short int -16 bits.


2 Answers

std::is_integer<T> does not exist.

That being said, std::numeric_limits<T>::is_integer does exist.

I'm not aware of any significant difference between std::numeric_limits<T>::is_integer and std::is_integral<T>. The latter was designed much later and became standard in C++11, whereas the former was introduced in C++98.

like image 140
Howard Hinnant Avatar answered Oct 03 '22 20:10

Howard Hinnant


There is no type T that has different results for std::is_integral<T>::value and std::numeric_limits<T>::is_integer. To quote the draft Standard:

3.9.1 Fundamental types [basic.fundamental]

7 Types bool, char, char16_t, char32_t, wchar_t, and the signed and unsigned integer types are collectively called integral types. A synonym for integral type is integer type.[...]

18.3.2.4 numeric_limits members [numeric.limits.members]

static constexpr bool is_integer; 

17 True if the type is integer.

20.9.4.1 Primary type categories [meta.unary.cat] (table 47)

template <class T> struct is_integral; 

T is an integral type (3.9.1)

like image 45
TemplateRex Avatar answered Oct 03 '22 21:10

TemplateRex