Namespaces
Variants
Views
Actions

C++ concepts: Compare

From cppreference.com
< cpp‎ | concept
Revision as of 20:19, 23 January 2014 by Cubbi (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 
 
 

The concept 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 type 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 Compare type, and false otherwise.

As with any BinaryPredicate, evaluation of that expression is not allowed to call non-const member functions of the dereferenced iterators.

[edit] Requirements

The type T satisfies Compare if

Given

  • comp, an object of type Compare
  • 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
  • For all a, comp(a,a)==false
  • If comp(a,b)==true then comp(b,a)==false
  • if comp(a,b)==true and comp(b,c)==true then comp(a,c)==true
equiv(a, b) bool Establishes equivalence relationship with the following properties
  • For all a, equiv(a,a)==true.
  • If equiv(a,b)==true, then equiv(b,a)==true
  • If equiv(a,b)==true and equiv(b,c)==true, then equiv(a,c)==true

Note: comp induces a strict total ordering on the equivalence classes determined by equiv

[edit] Standard library

The following standard library facilities expect a Compare 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 of std::forward_list) [edit]
sorts the elements
(public member function of std::list) [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 element not less than the given value
(function template) [edit]
returns an iterator to the first element greater than a certain value
(function template) [edit]
determines if an element exists in a certain 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 of std::forward_list) [edit]
merges two sorted lists
(public member function of std::list) [edit]
merges two ordered ranges in-place
(function template) [edit]
returns true if one set is a subset 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 larger of two elements
(function template) [edit]
returns the largest element in a range
(function template) [edit]
returns the smaller of two elements
(function template) [edit]
returns the smallest element in a range
(function template) [edit]
(C++11)
returns the larger and the smaller of two elements
(function template) [edit]
returns the smallest and the largest element in a range
(function template) [edit]
returns true 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]