Sometimes you want to check the type used to create a template. The standard library provides some handy routines to do this (defined in the file <type_traits>), like:
- std::is_arithmetic<T> – this is true if the type is floating point or integral data type (like int, unsigned short, float or double). Example:
-
1234bool value1 = std::is_arithmetic<int>::value; // truebool value2 = std::is_arithmetic<int*>::value; // falsebool value3 = std::is_arithmetic<bool>::value; // falsebool value4 = std::is_arithmetic<double>::value; // true
- std::is_integral<T> – this is true if the type is an integral data type (like int, unsigned short, bool, char or long). Example:
-
1234bool value1 = std::is_integral<int>::value; // truebool value2 = std::is_integral<int*>::value; // falsebool value3 = std::is_integral<bool>::value; // truebool value4 = std::is_integral<double>::value; // false
- std::is_floating_point<T> – this is true if the type is floating point type (float, double or long double). Example:
-
1234bool value1 = std::is_arithmetic<float>::value; // truebool value2 = std::is_arithmetic<int>::value; // falsebool value3 = std::is_arithmetic<bool>::value; // falsebool value4 = std::is_arithmetic<long double>::value; // true


