This header contains various compile-time functions for conditionally setting types, detecting types, or conditionally enabling functions.
| Syntax | Description |
typename conditional<bool B, TrueT, FalseT>::type
conditional_t<bool B, TrueT, FalseT> |
Selects between TrueT and FalseT based on the boolean value b. The chosen type is stored in conditional::type. - Template Parameters
-
| B | the value of the condition |
| TrueT | type to use when \(B == true\) |
| FalseT | type to use when \(B == false\) |
|
typename detect<DefaultT, DetectT<...>, ArgsT...>::type
detect_t<DefaultT, DetectT<...>, ArgsT...> |
Selects DetectT<ArgsT...> if it exists, otherwise selects DefaultT The chosen type is stored in detect::type and a boolean value is stored in detect::is_detected representing whether DetectT<ArgsT...> is found. - Template Parameters
-
| DefaultT | Default type |
| DetectT | Type to detect |
| ArgsT | Any template arguments for DetectT<ArgsT> |
|
typename enable_if<bool B, TypeT>::type
enable_if_t<bool B, TypeT> |
If B is true, define a public member type type. Otherwise, there is no member.
Example Usage template<typename TypeT,
enable_if_t<is_integral_v<TypeT>, bool> = true>
TypeT conditional_func() { return 0; }
- Template Parameters
-
| B | A boolean value |
| T | The type to conditionally define |
|