Type testing

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:
  • std::is_integral<T> – this is true if the type is an integral data type (like int, unsigned short, bool,  char or long). Example:
  • std::is_floating_point<T> – this is true if the type is floating point type (float, double or long double). Example:

 

Facebookgoogle_pluslinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *