C++ provides metaprogramming facilities, such as type traits, compile-time rational arithmetic, and compile-time integer sequences.
[edit] DefinitionsThe following types are collectively called referenceable types:
For any referenceable type T
, a reference to it can be created[1].
Type traits define compile-time template-based interfaces to query the properties of types.
Attempting to specialize a template defined in the <type_traits> header and listed in this page results in undefined behavior, except that std::common_type and std::basic_common_reference(since C++20) may be specialized as required in description.
A template defined in the <type_traits> header may be instantiated with an incomplete type unless otherwise specified, notwithstanding the general prohibition against instantiating standard library templates with incomplete types.
[edit] Base classesMost of non-transforming type traits need to be publicly and unambiguously derived from std::integral_constant in order to satisfy the requirements of UnaryTypeTrait or BinaryTypeTrait.
Two specializations of std::integral_constant for the type bool are provided:
[edit] Unary type traitsUnary type traits can be used to query the boolean properties of a type at compile time.
All these type traits satisfy UnaryTypeTrait, the base characteristic of each type trait is either std::true_type or std::false_type, depending on whether the corresponding condition is met.
[edit] Property queriesProperty query traits can be used to query the integral properties of a type at compile time.
All these type traits satisfy UnaryTypeTrait, the base characteristic of each type trait is std::integral_constant<std::size_t, Value>, where Value
is the query result of the corresponding property.
Type relationship traits can be used to query relationships between types at compile time.
All these type traits satisfy BinaryTypeTrait, the base characteristic of each type trait is either std::true_type or std::false_type, depending on whether the corresponding condition is met.
[edit] Type transformationsType transformation traits transform one type to another following some predefined rules.
All these type traits satisfy TransformationTrait.
[edit] Logical operations (since C++17)Logical operator traits apply logical operators to other type traits.
[edit] Member relationships (since C++20) [edit] Compile-time rational arithmeticThe header <ratio> provides types and functions for manipulating and storing compile-time ratios.
[edit] Compile-time integer sequences (since C++14)RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4