public member function
<set>

std::multiset::value_comp

value_compare value_comp() const;
Return comparison object
Returns a copy of the comparison object used by the container.

By default, this is a less object, which returns the same asoperator<.

This object determines the order of the elements in the container: it is a function pointer or a function object that takes two arguments of the same type as the container elements, and returnstrueif the first argument is considered to go before the second in the strict weak ordering it defines, andfalse否则为 false。

Two elements of a multiset are considered equivalent ifvalue_comp返回 11。falsereflexively (i.e., no matter the order in which the elements are passed as arguments).

In multiset containers, the keys to sort the elements are the values themselves, thereforevalue_compand its sibling member function key_comp are equivalent.

参数



返回值

The comparison object.
成员类型value_compareis the type of the comparison object associated to the container, defined in multiset as an alias of its second template parameter (Compare).

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// multiset::value_comp
#include <iostream>
#include <set>

int main ()
{
  std::multiset<int> mymultiset;

  std::multiset<int>::value_compare mycomp = mymultiset.value_comp();

  for (int i=0; i<7; i++) mymultiset.insert(i);

  std::cout << "mymultiset contains:";

  int highest = *mymultiset.rbegin();
  std::multiset<int>::iterator it = mymultiset.begin();
  do {
    std::cout << ' ' << *it;
  } while ( mycomp(*it++,highest) );

  std::cout << '\n';

  return 0;
}

输出
mymultiset contains: 0 1 2 3 4 5 6


复杂度

常量。

迭代器有效性

没有变化。

数据竞争

访问容器。
同时访问 multiset 的元素是安全的。

异常安全

强保证:如果抛出异常,容器没有发生变化。

另见