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
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
|
// 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) |
|