When doing template metaprogramming, you may often find yourself in situations where you need information about the types you are dealing with at compile time. When writing regular (non-generic) C++ code, we work with concrete types that we have complete knowledge about, but this is not the case when writing a template; the concrete types are not determined until a template is being instantiated by the compiler. Type traits let us extract information about the types our templates are dealing with in order to generate efficient and correct C++ code.
In order to extract information about template types, the standard library provides a type traits library, which is available in the
<type_traits> header. All type traits are evaluated at compile time.
Type trait categories
- Type traits that return information about a type as a boolean or an integer value.
- Type traits that return a new type. These type...