在线文档教程

Compare

C++概念:比较

概念Compare是用户提供的函数对象类型中的一些标准库工具所期望的一组需求。

应用于类型对象的函数调用操作的返回值。Compare,何时上下文转换到bool,产量true如果调用的第一个参数出现在严格弱序关系由此引发Compare类型,以及false否则。

就像任何BinaryPredicate,该表达式的求值不允许调用取消引用的迭代器的非Const成员函数。

所需

类型T满足Compare如果。

  • 类型T满足BinaryPredicate,和给予。

  • comp,类型的对象Compare

  • equiv(a, b),相当于!comp(a, b) && !comp(b, a)

下列表达式必须有效并具有指定的效果。

ExpressionReturn typeRequirements
comp(a, b)implicitly convertible to boolEstablishes 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)boolEstablishes 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

  • 为所有人a,,,comp(a,a)==false

  • 如果comp(a,b)==true然后comp(b,a)==false

  • 如果comp(a,b)==truecomp(b,c)==true然后comp(a,c)==true

`equiv(a, b)` `bool` Establishes equivalence relationship with the following properties

  • 为所有人a,,,equiv(a,a)==true

  • 如果equiv(a,b)==true,然后equiv(b,a)==true

  • 如果equiv(a,b)==trueequiv(b,c)==true,然后equiv(a,c)==true

注:comp诱导严格全序关于由equiv...

标准库

以下标准库设施期望Compare类型。

setcollection of unique keys, sorted by keys (class template)
mapcollection of key-value pairs, sorted by keys, keys are unique (class template)
multisetcollection of keys, sorted by keys (class template)
multimapcollection of key-value pairs, sorted by keys (class template)
priority_queueadapts a container to provide priority queue (class template)
sortsorts a range into ascending order (function template)
sortsorts the elements (public member function of std::forward_list)
sortsorts the elements (public member function of std::list)
stable_sortsorts a range of elements while preserving order between equal elements (function template)
partial_sortsorts the first N elements of a range (function template)
partial_sort_copycopies and partially sorts a range of elements (function template)
is_sorted (C++11)checks whether a range is sorted into ascending order (function template)
is_sorted_until (C++11)finds the largest sorted subrange (function template)
nth_elementpartially sorts the given range making sure that it is partitioned by the given element (function template)
lower_boundreturns an iterator to the first element not less than the given value (function template)
upper_boundreturns an iterator to the first element greater than a certain value (function template)
binary_searchdetermines if an element exists in a certain range (function template)
equal_rangereturns range of elements matching a specific key (function template)
mergemerges two sorted ranges (function template)
mergemerges two sorted lists (public member function of std::forward_list)
mergemerges two sorted lists (public member function of std::list)
inplace_mergemerges two ordered ranges in-place (function template)
includesreturns true if one set is a subset of another (function template)
set_differencecomputes the difference between two sets (function template)
set_intersectioncomputes the intersection of two sets (function template)
set_symmetric_differencecomputes the symmetric difference between two sets (function template)
set_unioncomputes the union of two sets (function template)
push_heapadds an element to a max heap (function template)
pop_heapremoves the largest element from a max heap (function template)
make_heapcreates a max heap out of a range of elements (function template)
sort_heapturns a max heap into a range of elements sorted in ascending order (function template)
is_heap (C++11)checks if the given range is a max heap (function template)
is_heap_until (C++11)finds the largest subrange that is a max heap (function template)
maxreturns the greater of the given values (function template)
max_elementreturns the largest element in a range (function template)
minreturns the smaller of the given values (function template)
min_elementreturns the smallest element in a range (function template)
minmax (C++11)returns the smaller and larger of two elements (function template)
minmax_element (C++11)returns the smallest and the largest elements in a range (function template)
lexicographical_comparereturns true if one range is lexicographically less than another (function template)
next_permutationgenerates the next greater lexicographic permutation of a range of elements (function template)
prev_permutationgenerates the next smaller lexicographic permutation of a range of elements (function template)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/概念性/比较