Files
cppdraft_translate/cppdraft/concept/booleantestable.md
2025-10-25 03:02:53 +03:00

6.4 KiB
Raw Permalink Blame History

[concept.booleantestable]

18 Concepts library [concepts]

18.5 Comparison concepts [concepts.compare]

18.5.2 Boolean testability [concept.booleantestable]

1

#

The exposition-only boolean-testable concept specifies the requirements on expressions that are convertible to bool and for which the logical operators ([expr.log.and], [expr.log.or], [expr.unary.op]) have the conventional semantics.

🔗

template<class T> concept [boolean-testable-impl](#concept:boolean-testable-impl "18.5.2Boolean testability[concept.booleantestable]") = [convertible_to](concept.convertible#concept:convertible_to "18.4.4Concept convertible_­to[concept.convertible]")<T, bool>; // exposition only

2

#

Let e be an expression such thatdecltype((e)) is T.

T models boolean-testable-impl only if

either remove_cvref_t is not a class type, or a search for the names operator&& and operator|| in the scope of remove_cvref_t finds nothing; and

argument-dependent lookup ([basic.lookup.argdep]) for the names operator&& and operator|| with T as the only argument type finds no disqualifying declaration (defined below).

3

#

A disqualifying parameter is a function parameter whose declared type P

is not dependent on a template parameter, and there exists an implicit conversion sequence ([over.best.ics]) from e to P; or

is dependent on one or more template parameters, and either

P contains no template parameter that participates in template argument deduction ([temp.deduct.type]), or

template argument deduction using the rules for deducing template arguments in a function call ([temp.deduct.call]) ande as the argument succeeds.

4

#

A key parameter of a function template D is a function parameter of type cv X or reference thereto, where X names a specialization of a class template that has the same innermost enclosing non-inline namespace as D, andX contains at least one template parameter that participates in template argument deduction.

[Example 1:

Innamespace Z {template struct C {}; templatevoid operator&&(C x, T y); templatevoid operator||(C<type_identity_t> x, T y);} the declaration of Z::operator&& contains one key parameter, C x, and the declaration of Z::operator|| contains no key parameters.

— end example]

5

#

A disqualifying declaration is

a (non-template) function declaration that contains at least one disqualifying parameter; or

a function template declaration that contains at least one disqualifying parameter, where

at least one disqualifying parameter is a key parameter; or

the declaration contains no key parameters; or

the declaration declares a function template to which no name is bound ([dcl.meaning]).

6

#

[Note 1:

The intention is to ensure that given two types T1 and T2 that each model boolean-testable-impl, the && and || operators within the expressionsdeclval() && declval() anddeclval() || declval() resolve to the corresponding built-in operators.

— end note]

🔗

template<class T> concept [boolean-testable](#concept:boolean-testable "18.5.2Boolean testability[concept.booleantestable]") = // exposition only [boolean-testable-impl](#concept:boolean-testable-impl "18.5.2Boolean testability[concept.booleantestable]")<T> && requires(T&& t) { { !std::forward<T>(t) } -> [boolean-testable-impl](#concept:boolean-testable-impl "18.5.2Boolean testability[concept.booleantestable]"); };

7

#

Let e be an expression such thatdecltype((e)) is T.

T models boolean-testable only ifbool(e) == !bool(!e).

8

#

[Example 2:

The typesbool,true_type ([meta.type.synop]),int*, andbitset::reference ([template.bitset]) model boolean-testable.

— end example]