This is pure syntactic sugar. Often we use, for example, sending tags like this:
void foo_impl(std::false_type) { } void foo_impl(std::true_type ) { } template <typename T> void foo(T) { foo_impl(t, std::bool_constant<std::is_integral<T>{} && !std::is_same<char, T>{}>()); }
Without bool_constant we will need to use a longer specifier type to indicate the type we need: std::integral_constant<bool, ...> . Since using integral_constant for boolean values pops up especially often, a concise and short way to access specializations is required, and bool_constant does. In fact, bool_constant is nothing more than an alias pattern for the bool specialization integral_constant :
template <bool B> using bool_constant = integral_constant<bool, B>;
The only reason ads for true_type and false_type (and other uses of integral_constant<bool, ..> ) were changed for brevity in standard, even; There was no technical need, since integral_constant<bool, false> and bool_constant<false> denote the same type.
source share