Understanding and defining type traits
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:
template <typename T> struct is_floating_point { static const bool value = false; }; template <> struct is_floating_point<float> { static const bool value = true; }; template <> struct is_floating_point<double> { static const bool value = true; }; template <> struct is_floating_point<long double> { static const...