equal_range

Syntax:

    #include <map>
    pair<iterator, iterator> equal_range( const key_type& key );
    pair<const_iterator, const_iterator> equal_range( const key_type& key ) const;

The function equal_range() returns two iterators - one to the first element that contains key, another to a point just after the last element that contains key.

For example, here is a hypothetical input-configuration loader using multimaps, strings and equal_range():

  multimap<string,pair<int,int> > input_config;
 
  // read configuration from file "input.conf" to input_config
  readConfigFile( input_config, "input.conf" );
 
  pair<multimap<string,pair<int,int> >::iterator,multimap<string,pair<int,int> >::iterator> ii;
  multimap<string,pair<int,int> >::iterator i;
 
  ii = input_config.equal_range("key");         // keyboard key-bindings
  // we can iterate over a range just like with begin() and end()
  for( i = ii.first; i != ii.second; ++i ) {
    // add a key binding with this key and output
    bindkey(i->second.first, i->second.second);
  }
 
  ii = input_config.equal_range("joyb");        // joystick button key-bindings
  for( i = ii.first; i != ii.second; ++i ) {
    // add a key binding with this joystick button and output
    bindjoyb(i->second.first, i->second.second);
  }