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


map::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. In map containers, where no duplicate keys are allowed, the range will include one element at most.

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 map::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 map 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 map 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
// map::equal_elements
#include <iostream>
#include <map>
using namespace std;
int main ()
{
  map<char,int> mymap;
  pair<map<char,int>::iterator,map<char,int>::iterator> ret;
  mymap['a']=10;
  mymap['b']=20;
  mymap['c']=30;
  ret = mymap.equal_range('b');
  cout << "lower bound points to: ";
  cout << ret.first->first << " => " << ret.first->second << endl;
  cout << "upper bound points to: ";
  cout << ret.second->first << " => " << ret.second->second << endl;
  return 0;
}


lower bound points to: 'b' => 20
upper bound points to: 'c' => 30

Complexity

Logarithmic in size.

See also