Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      C++ named requirements:EqualityComparable

      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 satisfiesEqualityComparable if given expressionsa,b andc of typeT or(since C++11)const T, the following expression is valid and has its specified effects:

       Expression TypeEffects
      a== bmeetsBooleanTestable
      (until C++20)
      Establishes anequivalence relation, that is, it satisfies the following properties:
      • For all values ofa,a== a yieldstrue.
      • Ifa== b, thenb== a.
      • Ifa== b andb== c, thena== 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 283C++98even ifT isEqualityComparable, the
      requirements did not apply toconst T objects
      they apply to
      const T instead ofT
      LWG 2114
      (P2167R3)
      C++98convertibility tobool was too weak to reflect the expectation of implementationsrequirements strengthened

      [edit]See also

      specifies that operator== is an equivalence relation
      (concept)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/named_req/EqualityComparable&oldid=175964"

      [8]ページ先頭

      ©2009-2025 Movatter.jp