Difference between revisions of "cpp/named req/Compare"
m (→See also: fmt) |
(LWG 3031) |
||
Line 6: | Line 6: | ||
The return value of the function call operation applied to an object of a type satisfying {{named req/core|Compare}}, when [[cpp/language/implicit conversion|contextually converted]] to {{c|bool}}, yields {{c|true}} if the first argument of the call appears before the second in the ''strict weak ordering relation'' induced by this type, and {{c|false}} otherwise. | The return value of the function call operation applied to an object of a type satisfying {{named req/core|Compare}}, when [[cpp/language/implicit conversion|contextually converted]] to {{c|bool}}, yields {{c|true}} if the first argument of the call appears before the second in the ''strict weak ordering relation'' induced by this type, and {{c|false}} otherwise. | ||
− | As with any {{named req|BinaryPredicate}}, evaluation of that expression is not allowed to call non-const functions through the dereferenced iterators | + | As with any {{named req|BinaryPredicate}}, evaluation of that expression is not allowed to call non-const functions through the dereferenced iterators {{rev inl|since=c++20<!--LWG 3031-->| and, syntactically, the function call operation must accept {{tt|const}} object arguments, with the same behavior regardless of whether the arguments are {{tt|const}} or non-{{tt|const}}}}. |
===Requirements=== | ===Requirements=== |
Revision as of 02:49, 4 May 2022
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 satisfying Compare, when contextually converted to bool, yields true if the first argument of the call appears before the second in the strict weak ordering relation induced by this type, and false otherwise.
As with any BinaryPredicate, evaluation of that expression is not allowed to call non-const functions through the dereferenced iterators and, syntactically, the function call operation must accept const
object arguments, with the same behavior regardless of whether the arguments are const
or non-const
(since C++20).
Requirements
The type T
satisfies Compare if
- The type
T
satisfies BinaryPredicate, and
Given
-
comp
, an object of typeT
-
equiv(a, b)
, an expression equivalent to!comp(a, b) && !comp(b, a)
The following expressions must be valid and have their specified effects
Expression | Return type | Requirements |
---|---|---|
comp(a, b) | implicitly convertible to bool | Establishes strict weak ordering relation with the following properties
|
equiv(a, b) | bool | Establishes equivalence relationship with the following properties
|
Note: comp
induces a strict total ordering on the equivalence classes determined by equiv
Standard library
The following standard library facilities expect a Compare type.
collection of unique keys, sorted by keys (class template) | |
collection of key-value pairs, sorted by keys, keys are unique (class template) | |
collection of keys, sorted by keys (class template) | |
collection of key-value pairs, sorted by keys (class template) | |
adapts a container to provide priority queue (class template) | |
sorts a range into ascending order (function template) | |
sorts the elements (public member function of std::forward_list<T,Allocator> )
| |
sorts the elements (public member function of std::list<T,Allocator> )
| |
sorts a range of elements while preserving order between equal elements (function template) | |
sorts the first N elements of a range (function template) | |
copies and partially sorts a range of elements (function template) | |
(C++11) |
checks whether a range is sorted into ascending order (function template) |
(C++11) |
finds the largest sorted subrange (function template) |
partially sorts the given range making sure that it is partitioned by the given element (function template) | |
returns an iterator to the first element not less than the given value (function template) | |
returns an iterator to the first element greater than a certain value (function template) | |
determines if an element exists in a partially-ordered range (function template) | |
returns range of elements matching a specific key (function template) | |
merges two sorted ranges (function template) | |
merges two sorted lists (public member function of std::forward_list<T,Allocator> )
| |
merges two sorted lists (public member function of std::list<T,Allocator> )
| |
merges two ordered ranges in-place (function template) | |
returns true if one sequence is a subsequence of another (function template) | |
computes the difference between two sets (function template) | |
computes the intersection of two sets (function template) | |
computes the symmetric difference between two sets (function template) | |
computes the union of two sets (function template) | |
adds an element to a max heap (function template) | |
removes the largest element from a max heap (function template) | |
creates a max heap out of a range of elements (function template) | |
turns a max heap into a range of elements sorted in ascending order (function template) | |
(C++11) |
checks if the given range is a max heap (function template) |
(C++11) |
finds the largest subrange that is a max heap (function template) |
returns the greater of the given values (function template) | |
returns the largest element in a range (function template) | |
returns the smaller of the given values (function template) | |
returns the smallest element in a range (function template) | |
(C++11) |
returns the smaller and larger of two elements (function template) |
(C++11) |
returns the smallest and the largest elements in a range (function template) |
returns true if one range is lexicographically less than another (function template) | |
generates the next greater lexicographic permutation of a range of elements (function template) | |
generates the next smaller lexicographic permutation of a range of elements (function template) |
See also
(C++20) |
specifies that a relation imposes a strict weak ordering (concept) |
Comparison operators | < , <= , > , >= , == , != , and <=> (C++20), compare the arguments
|