template< class B > concept __boolean_testable_impl = // exposition only std::convertible_to<B, bool>; | (since C++20) | |

template< class B > concept boolean-testable = // exposition only __boolean_testable_impl<B> && requires (B&& b) { { !std::forward<B>(b) } -> __boolean_testable_impl; }; | (since C++20) |

The exposition-only concept

specifies the requirements for expressions that are convertible to *boolean-testable*`bool`

and for which the logical operators have the usual behavior (including short-circuiting), even for two different

types.*boolean-testable*

Formally, to model the exposition-only concept

, the type must not define any member *__boolean_testable_impl*`operator&&`

and `operator||`

, and no viable non-member `operator&&`

and `operator||`

may be visible by argument-dependent lookup. Additionally, given an expression `e`

such that `decltype((e))`

is `B`

,

is modeled only if *boolean-testable*`bool(e) == !bool(!e)`

.

Expressions declared in requires-expressions of the standard library concepts are required to be equality-preserving (except where stated otherwise).

Examples of

types include *boolean-testable*`bool`

, `std::true_type`

, `std::bitset<N>::reference`

, and `int*`

.

© cppreference.com

Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.

https://en.cppreference.com/w/cpp/concepts/boolean-testable