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 as operator<.

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 returns true if the first argument is considered to go before the second in the strict weak ordering it defines, and false otherwise.

Two elements of a multiset are considered equivalent if value_comp returns false reflexively (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, therefore value_comp and its sibling member function key_comp are equivalent.

Parameters

none

Return value

The comparison object.
Member type value_compare is the type of the comparison object associated to the container, defined in multiset as an alias of its second template parameter (Compare).

Example

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;
}


Output:
mymultiset contains: 0 1 2 3 4 5 6

Complexity

Constant.

Iterator validity

No changes.

Data races

The container is accessed.
Concurrently accessing the elements of a multiset is safe.

Exception safety

Strong guarantee: if an exception is thrown, there are no changes in the container.

See also

  • 9281021542 2018-02-20
  • 632231541 2018-02-20
  • 9751491540 2018-02-20
  • 8333621539 2018-02-20
  • 995001538 2018-02-20
  • 6477441537 2018-02-20
  • 511981536 2018-02-19
  • 2072881535 2018-02-19
  • 6024461534 2018-02-19
  • 7594061533 2018-02-19
  • 9311341532 2018-02-19
  • 4928331531 2018-02-19
  • 38561530 2018-02-19
  • 7776611529 2018-02-19
  • 3038041528 2018-02-19
  • 9566341527 2018-02-19
  • 3936031526 2018-02-19
  • 9531111525 2018-02-19
  • 291211524 2018-02-19
  • 8962001523 2018-02-19