cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : multiset : equal_range
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
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::equal_range public member function
pair<iterator,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 nearest value greater than x, if any, or to multiset::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 multiset containers as an alias of Key, which is the first template parameter and the type of 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).
iterator is a member type, defined in multiset as a bidirectional iterator type.

Example

// multiset::equal_elements
#include <iostream>
#include <set>
using namespace std;

int main ()
{
  multiset<int>::iterator it;
  pair<multiset<int>::iterator,multiset<int>::iterator> ret;

  int myints[]= {77,30,16,2,30,30};
  multiset<int> mymultiset (myints, myints+6); // 2 16 30 30 30 77

  ret = mymultiset.equal_range(30);            //      ^        ^

  for (it=ret.first; it!=ret.second; ++it)
    ++(*it);                                   // 2 16 31 31 31 77

  cout << "mymultiset contains:";
  for (it=mymultiset.begin(); it!=mymultiset.end(); ++it)
    cout << " " << *it;
  cout << endl;

  return 0;
}

multiset contains: 2 16 31 31 31 77

Complexity

Logarithmic in size.

See also

multiset::count Count elements with a specific key (public member function)
multiset::lower_bound Return iterator to lower bound (public member function)
multiset::upper_bound Return iterator to upper bound (public member function)
multiset::find Get iterator to element (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us