Exploring the Standard Type Traits: Part 2
Understand type transformation using metafunctions in C++ template metaprogramming.
We'll cover the following...
Modifying cv-specifiers, references, pointers, or a sign
The type traits that are performing transformations on types are also called metafunctions. These type traits provided a member type (typedef
) called type
that represents the transformed type. This category of type traits includes the following:
Type Traits for Certain Transformations
Name | Description |
| Add the |
| Remove the |
| Add an Ivalue or value reference to a type. |
| Removes a reference (either value or rvalue) from a type. |
| Removes the |
| Adds a pointer to a type. |
| Removes a pointer from a type. |
| Make an integral type (except for |
| Remove one or all extents from an array type. |
With the exception of remove_cvref
, which was added in C++20, all the other type traits listed in this table are available in C++11. These aren’t all the metafunctions from the standard library. More are listed next.
Miscellaneous transformations
Apart from the metafunctions previously listed, there are other type traits performing type transformations. The most important of these are listed in the following table:
Type Traits for Miscellaneous Transformationas
Name | C++ Version | Description |
| C++11 | Enables the removal of a function overload or template specialization from overload resolution. |
| C++11 | Defines the member type called |
| C++11 | Applies transformations on a type (array-to-pointer for array types, Ivalue-to-rvalue for reference types, and function-to-pointer for function types), removes |
| C++11 | Determines the common type from a group of types. |
| C++20 | Determines the common reference type from a group of types. |
| C++11 | Determines the underlying type of an enumeration type. |
| C++17 | A type alias mapping a sequence a of types to the |
| C++20 | Provides the member typedef |