[concept.booleantestable] # 18 Concepts library [[concepts]](./#concepts) ## 18.5 Comparison concepts [[concepts.compare]](concepts.compare#concept.booleantestable) ### 18.5.2 Boolean testability [concept.booleantestable] [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L859) The exposition-only [*boolean-testable*](#concept:boolean-testable "18.5.2 Boolean testability [concept.booleantestable]") concept specifies the requirements on expressions that are convertible to bool and for which the logical operators ([[expr.log.and]](expr.log.and "7.6.14 Logical AND operator"), [[expr.log.or]](expr.log.or "7.6.15 Logical OR operator"), [[expr.unary.op]](expr.unary.op "7.6.2.2 Unary operators")) have the conventional semantics[.](#1.sentence-1) [🔗](#concept:boolean-testable-impl) `template concept [boolean-testable-impl](#concept:boolean-testable-impl "18.5.2 Boolean testability [concept.booleantestable]") = [convertible_to](concept.convertible#concept:convertible_to "18.4.4 Concept convertible_­to [concept.convertible]"); // exposition only ` [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L871) Let e be an expression such thatdecltype((e)) is T[.](#2.sentence-1) T models [*boolean-testable-impl*](#concept:boolean-testable-impl "18.5.2 Boolean testability [concept.booleantestable]") only if - [(2.1)](#2.1) 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 - [(2.2)](#2.2) argument-dependent lookup ([[basic.lookup.argdep]](basic.lookup.argdep "6.5.4 Argument-dependent name lookup")) for the names operator&& and operator|| with T as the only argument type finds no disqualifying declaration (defined below)[.](#2.sentence-2) [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L889) A [*disqualifying parameter*](#def:parameter,disqualifying "18.5.2 Boolean testability [concept.booleantestable]") is a function parameter whose declared type P - [(3.1)](#3.1) is not dependent on a template parameter, and there exists an implicit conversion sequence ([[over.best.ics]](over.best.ics "12.2.4.2 Implicit conversion sequences")) from e to P; or - [(3.2)](#3.2) is dependent on one or more template parameters, and either * [(3.2.1)](#3.2.1) P contains no template parameter that participates in template argument deduction ([[temp.deduct.type]](temp.deduct.type "13.10.3.6 Deducing template arguments from a type")), or * [(3.2.2)](#3.2.2) template argument deduction using the rules for deducing template arguments in a function call ([[temp.deduct.call]](temp.deduct.call "13.10.3.2 Deducing template arguments from a function call")) ande as the argument succeeds[.](#3.sentence-1) [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L912) A [*key parameter*](#def:parameter,key "18.5.2 Boolean testability [concept.booleantestable]") 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[.](#4.sentence-1) [*Example [1](#example-1)*: Innamespace Z {template struct C {}; templatevoid operator&&(C x, T y); templatevoid operator||(C> x, T y);} the declaration of Z​::​operator&& contains one key parameter, C x, and the declaration of Z​::​operator|| contains no key parameters[.](#4.sentence-2) — *end example*] [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L937) A [*disqualifying declaration*](#def:declaration,disqualifying "18.5.2 Boolean testability [concept.booleantestable]") is - [(5.1)](#5.1) a (non-template) function declaration that contains at least one disqualifying parameter; or - [(5.2)](#5.2) a function template declaration that contains at least one disqualifying parameter, where * [(5.2.1)](#5.2.1) at least one disqualifying parameter is a key parameter; or * [(5.2.2)](#5.2.2) the declaration contains no key parameters; or * [(5.2.3)](#5.2.3) the declaration declares a function template to which no name is bound ([[dcl.meaning]](dcl.meaning "9.3.4 Meaning of declarators"))[.](#5.sentence-1) [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L955) [*Note [1](#note-1)*: The intention is to ensure that given two types T1 and T2 that each model [*boolean-testable-impl*](#concept:boolean-testable-impl "18.5.2 Boolean testability [concept.booleantestable]"), the && and || operators within the expressionsdeclval() && declval() anddeclval() || declval() resolve to the corresponding built-in operators[.](#6.sentence-1) — *end note*] [🔗](#concept:boolean-testable) `template concept [boolean-testable](#concept:boolean-testable "18.5.2 Boolean testability [concept.booleantestable]") = // exposition only [boolean-testable-impl](#concept:boolean-testable-impl "18.5.2 Boolean testability [concept.booleantestable]") && requires(T&& t) { { !std::forward(t) } -> [boolean-testable-impl](#concept:boolean-testable-impl "18.5.2 Boolean testability [concept.booleantestable]"); }; ` [7](#7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L974) Let e be an expression such thatdecltype((e)) is T[.](#7.sentence-1) T models [*boolean-testable*](#concept:boolean-testable "18.5.2 Boolean testability [concept.booleantestable]") only ifbool(e) == !bool(!e)[.](#7.sentence-2) [8](#8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L980) [*Example [2](#example-2)*: The typesbool,true_type ([[meta.type.synop]](meta.type.synop "21.3.3 Header synopsis")),int*, andbitset​::​reference ([[template.bitset]](template.bitset "22.9.2 Class template bitset")) model [*boolean-testable*](#concept:boolean-testable "18.5.2 Boolean testability [concept.booleantestable]")[.](#8.sentence-1) — *end example*]