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
multimap
comparison operators
multimap::multimap
multimap::~multimap
member functions:
multimap::begin
multimap::clear
multimap::count
multimap::empty
multimap::end
multimap::equal_range
multimap::erase
multimap::find
multimap::get_allocator
multimap::insert
multimap::key_comp
multimap::lower_bound
multimap::max_size
multimap::operator=
multimap::rbegin
multimap::rend
multimap::size
multimap::swap
multimap::upper_bound
multimap::value_comp


multimap::equal_range

public member function
pair<iterator,iterator>
   equal_range ( const key_type& x );
pair<const_iterator,const_iterator>
   equal_range ( const key_type& x ) const;

Get range of equal elements

Returns the bounds of a range that includes all the elements in the container with a key that compares equal to x.

If x does not match any key in the container, the range returned has a length of zero, with both iterators pointing to the element with nearest key greater than x, if any, or to multimap::end if x is greater than all the elements in the container.

Parameters

x
Key value to be compared.
key_type is a member type defined in multimap containers as an alias of Key, which is the first template parameter and the type of the keys for the elements stored in the container.

Return value

The function returns a pair, where its member pair::first is an iterator to the lower bound of the range with the same value as the one that would be returned by lower_bound(x), and pair::second is an iterator to the upper bound of the range with the same value as the one that would be returned by upper_bound(x).

Both iterator and const_iterator are member types. In the multimap class template, these are bidirectional iterators.
Dereferencing any of these iterators accesses the element's value, which is of type pair<const Key,T>.

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
29
30
31
// multimap::equal_elements
#include <iostream>
#include <map>
using namespace std;
int main ()
{
  multimap<char,int> mymm;
  multimap<char,int>::iterator it;
  pair<multimap<char,int>::iterator,multimap<char,int>::iterator> ret;
  mymm.insert(pair<char,int>('a',10));
  mymm.insert(pair<char,int>('b',20));
  mymm.insert(pair<char,int>('b',30));
  mymm.insert(pair<char,int>('b',40));
  mymm.insert(pair<char,int>('c',50));
  mymm.insert(pair<char,int>('c',60));
  mymm.insert(pair<char,int>('d',60));
  cout << "mymm contains:\n";
  for (char ch='a'; ch<='d'; ch++)
  {
    cout << ch << " =>";
    ret = mymm.equal_range(ch);
    for (it=ret.first; it!=ret.second; ++it)
      cout << " " << (*it).second;
    cout << endl;
  }
  return 0;
}


mymm contains:
a => 10
b => 20 30 40
c => 50 60
d => 60

Complexity

Logarithmic in size.

See also