fennec
Loading...
Searching...
No Matches
Conditional Types

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
Bthe value of the condition
TrueTtype to use when \(B == true\)
FalseTtype 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
DefaultTDefault type
DetectTType to detect
ArgsTAny 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
BA boolean value
TThe type to conditionally define