Tutorial by Examples

C++11 The type_traits header contains a set of template classes and helpers to transform and check properties of types at compile-time. These traits are typically used in templates to check for user errors, support generic programming, and allow for optimizations. Most type traits are used to c...
C++11 The std::is_same<T, T> type relation is used to compare two types. It will evaluate as boolean, true if the types are the same and false if otherwise. e.g. // Prints true on most x86 and x86_64 compilers. std::cout << std::is_same<int, int32_t>::value << "\n&qu...
C++11 There are a number of different type traits that compare more general types. Is Integral: Evaluates as true for all integer types int, char, long, unsigned int etc. std::cout << std::is_integral<int>::value << "\n"; // Prints true. std::cout << std::is_in...
C++11 Type properties compare the modifiers that can be placed upon different variables. The usefulness of these type traits is not always obvious. Note: The example below would only offer an improvement on a non-optimizing compiler. It is a simple a proof of concept, rather than complex example. ...

Page 1 of 1