Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      C++ named requirements:LessThanComparable

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

      The type must work with< operator and the result should have standard semantics.

      Contents

      [edit]Requirements

      The typeT satisfiesLessThanComparable if given expressionsa,b andc of typeT orconst T(since C++11), the following expression is valid and has its specified effects:

       Expression TypeEffects
      a< bmeetsBooleanTestable
      (until C++20)
      Establishesstrict weak ordering relation with the following properties:
      • For alla,!(a< a) yieldstrue.
      • Ifa< b, then!(b< a).
      • Ifa< b andb< c, thena< c.
      • Definingequiv(a, b) as!(a< b)&&!(b< a), ifequiv(a, b) andequiv(b, c), thenequiv(a, c).
      modelsboolean-testable
      (since C++20)

      [edit]Notes

      To satisfy this requirement, types that do not have built-incomparison operators have to provide auser-definedoperator<.

      For the types that are bothEqualityComparable andLessThanComparable, the C++ standard library makes a distinction between

      • Equality, which is the value of the expressiona== b and
      • Equivalence, which is the value of the expression!(a< b)&&!(b< a).

      [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

      aBinaryPredicate that establishes an ordering relation
      (named requirement)
      specifies that arelation imposes a strict weak ordering
      (concept)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/named_req/LessThanComparable&oldid=175929"

      [8]ページ先頭

      ©2009-2025 Movatter.jp