Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      C++ named requirements:BooleanTestable

      From cppreference.com
      <cpp‎ |named req
       
       
      C++ named requirements
       

      Specifies that an expression of such a type and value category is convertible tobool, and for which the logical operators for the type or two differentBooleanTestable types have the usual behavior (includingshort-circuiting).

      Contents

      [edit]Requirements

      Lete be an expression of a certain type and value category. The type and value category meet theBooleanTestable requirements if:

      • !e is well-formed and does not modify the object denoted bye, if any, except that ife is an xvalue, the denoted object can be left in a valid but unspecified state(since C++11).
      • Bothe and!e are convertible tobool by bothimplicit conversion andstatic_cast.
      • Conversions in both manners produce equal results and do not modify the source object, if any, except that ife or!e is an xvalue, the source object can be left in a valid but unspecified state(since C++11).
      • bool(!e)==!bool(e) holds.
      • No viable non-memberoperator&& andoperator|| is visible byargument-dependent lookup for the type ofe or!e.
      • Ife or!e is of a class type, the class does not define any memberoperator&& oroperator||.

      [edit]Notes

      The standard does not define a named requirement with this name. It was originally proposed in an early resolution ofLWG2114, but was superseded by the exposition-only conceptboolean-testable in the final resolutionP2167R3. Because implementations generally expect the provided types to modelboolean-testable even in pre-C++20 modes, we intentedly treat P2167R3 as a defect report and transform theboolean-testable to legacy named requirements.

      When the&& and|| operators are used with operands whose type and value category areBooleanTestable, built-in versions are selected and short-circuit evaluation is performed.

      The type and value category of an expressione meet theBooleanTestable requirements if and only ifdecltype((e)) modelsboolean-testable.

      (since C++20)

      Examples ofBooleanTestable types (with any value category) includebool,std::true_type(since C++11),std::bitset<N>::reference, andint*.

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2114
      (P2167R3)
      C++98convertibility tobool was too weak to reflect the expectation of implementationsrequirements strengthened

      [edit]See also

       (C++20)
      specifies that a type can be used in Boolean contexts
      (exposition-only concept*)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/named_req/BooleanTestable&oldid=175968"

      [8]ページ先頭

      ©2009-2025 Movatter.jp