Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
multiset
comparison operators
multiset::multiset
multiset::~multiset
member functions:
multiset::begin
multiset::clear
multiset::count
multiset::empty
multiset::end
multiset::equal_range
multiset::erase
multiset::find
multiset::get_allocator
multiset::insert
multiset::key_comp
multiset::lower_bound
multiset::max_size
multiset::operator=
multiset::rbegin
multiset::rend
multiset::size
multiset::swap
multiset::upper_bound
multiset::value_comp


multiset::key_comp

public member function
key_compare key_comp ( ) const;

Return comparison object

Returns the comparison object associated with the container, which can be used to compare two elements of the container.

This comparison object is set on object construction, and may either be a pointer to a function or an object of a class with a function call operator. In both cases it 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 the object defines, and false otherwise.

In multiset containers, the element values are the keys themselves, therefore key_comp and its sibling member function value_comp both return the same.

Parameters

none

Return value

The comparison object.
multiset::key_compare is a member type defined to Compare, which is the second template parameter in the multiset class template.

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
25
26
27
28
// multiset::key_comp
#include <iostream>
#include <set>
using namespace std;
int main ()
{
  multiset<int> mymultiset;
  multiset<int>::key_compare mycomp;
  multiset<int>::iterator it;
  int i,highest;
  mycomp = mymultiset.key_comp();
  for (i=0; i<=5; i++) mymultiset.insert(i);
  cout << "mymultiset contains:";
  highest=*mymultiset.rbegin();
  it=mymultiset.begin();
  do {
    cout << " " << *it;
  } while ( mycomp(*it++,highest) );
  cout << endl;
  return 0;
}


Output:
mymultiset contains: 0 1 2 3 4 5

Complexity

Constant.

See also