

/ The type used as a compile-time boolean with true value.

false_type and true_type are two helper classes defined below:Ĭonstexpr operator value_type() Here we specify template is_const to be derived class of false_type and true type.
C KNIGHTS AN INTRODUCTION TO PROGRAMMING IN C CODE
For instance, the following code can be found in the header file in g++ 4.8.1. You can also find more information about the usage of these templates by following the link provided.Īs for the implementation, the functionalities for the Type Traits usually rely on the template specifications type by type, which is a common method in template metaprogramming. You can find all the latest definitions and descriptions of Type Traits from the link above. Apart from determining the traits of types, in, there also exist frequently used class templates such as is_same and enable_if. And as the language evolves, Type Traits have been constantly modified. In the original design, the C++ language designers categorized Type Traits in a simple way.

For more information, you can see the Primary type categories table at Using the function, we can determine whether the data is of POD type. In the standard library of C++11, template class is_pod is defined type_traits. In the example, function template _is_pod is defined as a wrapper for the static member of template class is_pod. In the book “Understanding C++11”, for instance, we used Type Traits to analyze the characteristics of types. That’s the key reason for the emergence of Type Trait. In many C++ programming practices, especially these in template metaprogramming, developers may find it difficult to build a template work for all types without knowing the characteristics of a type. As its name suggests, Type Traits exposes different characteristics of types, or simply the “type of type”. However, the T ype Traits feature is formally introduced into the C++ language in the C++11 standard library. The origin of Type Traits can be traced back to the TR1 and boost libraries.
