Understanding and Defining Type Traits

Learn the concept of type traits and how they are used in template metaprogramming.

In a nutshell, type traits are small class templates that contain a constant value whose value represents the answer to a question we ask about a type. An example of such a question is, Is this type a floating-point type? The technique for building type traits that provide such information about types relies on template specialization; we define a primary template as well as one or more specializations.

Let’s see how we can build a type trait that tells us, at compile-time, whether a type is a floating-point type:

Get hands-on with 1200+ tech skills courses.