| Start | ||||||
|---|---|---|---|---|---|---|
| Standard type traits The These traits are typically used in templates to check for user errors, support generic programming, and allow for optimizations. Most type traits are used to check if a type fulfils some criteria. These have the following form: If the template class is instantiated with a type which fulfils some criteria Constants
Functions
Returns
Returns Types
The trait can then be used in constructs such as There are also various traits which transform types, such as |
||||||
| Type Properties Type properties compare the modifiers that can be placed upon different variables. The usefulness of these type traits is not always obvious. Note: The example below would only offer an improvement on a non-optimizing compiler. It is a simple a proof of concept, rather than complex example. e.g. Fast divide by four. Is Constant: This will evaluate as true when type is constant. Is Volatile: This will evaluate as true when the type is volatile. Is signed: This will evaluate as true for all signed types. Is Unsigned: Will evaluate as true for all unsigned types. |
||||||
| Type relations with std::is_same<T, T> The e.g. The e.g. Using When combined with a static assert the e.g. A function that only allows input from an |
||||||
| Fundamental type traits There are a number of different type traits that compare more general types. Is Integral: Evaluates as true for all integer types Is Floating Point: Evaluates as true for all floating point types. Is Enum: Evaluates as true for all enumerated types, including Is Pointer: Evaluates as true for all pointers. Is Class: Evaluates as true for all classes and struct, with the exception of RemarksType traits are templated constructs used to compare and test the properties of different types at compile time. They can be used to provide conditional logic at compile time that can limit or extend the functionality of your code in a specific manner. The type traits library was brought in with the |
Read Article
https://develop.horje.com/learn/1434/reference