Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      C++ named requirements:Compare

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

      Compare is a set of requirements expected by some of the standard library facilities from the user-provided function object types.

      The return value of the function call operation applied to an object of a type satisfyingCompare, whenconverted tobool, yieldstrue if the first argument of the call appears before the second in thestrict weak ordering relation induced by this type, andfalse otherwise.

      As with anyBinaryPredicate, evaluation of that expression is not allowed to call non-const functions through the dereferenced iterators and, syntactically, the function call operation must acceptconst object arguments, with the same behavior regardless of whether the arguments areconst or non-const.

      Contents

      [edit]Requirements

      The typeT satisfiesCompare if

      Given

      The following expressions must be valid and have their specified effects:

      ExpressionReturn typeRequirements
      comp(a, b)

      meetsBooleanTestable

      (until C++20)

      modelsboolean-testable

      (since C++20)
      Establishesstrict weak ordering relation with the following properties:
      • For alla,comp(a, a)==false.
      • Ifcomp(a, b)==true thencomp(b, a)==false.
      • ifcomp(a, b)==true andcomp(b, c)==true thencomp(a, c)==true.
      equiv(a, b)boolEstablishesequivalence relationship with the following properties:
      • For alla,equiv(a, a)==true.
      • Ifequiv(a, b)==true, thenequiv(b, a)==true.
      • Ifequiv(a, b)==true andequiv(b, c)==true, thenequiv(a, c)==true.

      Note:comp induces astrict total ordering on the equivalence classes determined byequiv.

      [edit]Standard library

      The following standard library facilities expect aCompare type.

      collection of unique keys, sorted by keys
      (class template)[edit]
      collection of key-value pairs, sorted by keys, keys are unique
      (class template)[edit]
      collection of keys, sorted by keys
      (class template)[edit]
      collection of key-value pairs, sorted by keys
      (class template)[edit]
      adapts a container to provide priority queue
      (class template)[edit]
      sorts a range into ascending order
      (function template)[edit]
      sorts the elements
      (public member function ofstd::forward_list<T,Allocator>)[edit]
      sorts the elements
      (public member function ofstd::list<T,Allocator>)[edit]
      sorts a range of elements while preserving order between equal elements
      (function template)[edit]
      sorts the first N elements of a range
      (function template)[edit]
      copies and partially sorts a range of elements
      (function template)[edit]
      (C++11)
      checks whether a range is sorted into ascending order
      (function template)[edit]
      finds the largest sorted subrange
      (function template)[edit]
      partially sorts the given range making sure that it is partitioned by the given element
      (function template)[edit]
      returns an iterator to the first elementnot less than the given value
      (function template)[edit]
      returns an iterator to the first elementgreater than a certain value
      (function template)[edit]
      determines if an element exists in a partially-ordered range
      (function template)[edit]
      returns range of elements matching a specific key
      (function template)[edit]
      merges two sorted ranges
      (function template)[edit]
      merges two sorted lists
      (public member function ofstd::forward_list<T,Allocator>)[edit]
      merges two sorted lists
      (public member function ofstd::list<T,Allocator>)[edit]
      merges two ordered ranges in-place
      (function template)[edit]
      returnstrue if one sequence is a subsequence of another
      (function template)[edit]
      computes the difference between two sets
      (function template)[edit]
      computes the intersection of two sets
      (function template)[edit]
      computes the symmetric difference between two sets
      (function template)[edit]
      computes the union of two sets
      (function template)[edit]
      adds an element to a max heap
      (function template)[edit]
      removes the largest element from a max heap
      (function template)[edit]
      creates a max heap out of a range of elements
      (function template)[edit]
      turns a max heap into a range of elements sorted in ascending order
      (function template)[edit]
      (C++11)
      checks if the given range is a max heap
      (function template)[edit]
      finds the largest subrange that is a max heap
      (function template)[edit]
      returns the greater of the given values
      (function template)[edit]
      returns the largest element in a range
      (function template)[edit]
      returns the smaller of the given values
      (function template)[edit]
      returns the smallest element in a range
      (function template)[edit]
      (C++11)
      returns the smaller and larger of two elements
      (function template)[edit]
      returns the smallest and the largest elements in a range
      (function template)[edit]
      returnstrue if one range is lexicographically less than another
      (function template)[edit]
      generates the next greater lexicographic permutation of a range of elements
      (function template)[edit]
      generates the next smaller lexicographic permutation of a range of elements
      (function template)[edit]

      [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++98contextual convertibility of return types tobool did not
      reflect the practice of implementations
      requirements corrected
      LWG 3031C++98requirements onconst values were insufficentrequirements strengthened

      [edit]See also

      specifies that arelation imposes a strict weak ordering
      (concept)[edit]
      Comparison operators<,<=,>,>=,==,!=, and<=>(C++20), compare the arguments
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/named_req/Compare&oldid=175974"

      [8]ページ先頭

      ©2009-2025 Movatter.jp