public member function
<set>
std::multiset::equal_range
pair<iterator,iterator> equal_range (const value_type& val) const;
pair<const_iterator,const_iterator> equal_range (const value_type& val) const;
pair<iterator,iterator> equal_range (const value_type& val);
Get range of equal elements
Returns the bounds of a range that includes all the elements in the container that are equivalent to val.
If no matches are found, the range returned has a length of zero, with both iterators pointing to the first element that is considered to go after val according to the container's internal comparison object (key_comp).
Two elements of a multiset are considered equivalent if the container's comparison object returns false reflexively (i.e., no matter the order in which the elements are passed as arguments).
Parameters
- val
- Value to search for.
Member type value_type is the type of the elements in the container, defined in multiset as an alias of its first template parameter (T).
Return value
The function returns a pair, whose member pair::first is the lower bound of the range (the same as lower_bound), and pair::second is the upper bound (the same as upper_bound).
Member types iterator and const_iterator are bidirectional iterator types pointing to elements.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
// multiset::equal_elements
#include <iostream>
#include <set>
typedef std::multiset<int>::iterator It; // aliasing the iterator type used
int main ()
{
int myints[]= {77,30,16,2,30,30};
std::multiset<int> mymultiset (myints, myints+6); // 2 16 30 30 30 77
std::pair<It,It> ret = mymultiset.equal_range(30); // ^ ^
mymultiset.erase(ret.first,ret.second);
std::cout << "mymultiset contains:";
for (It it=mymultiset.begin(); it!=mymultiset.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
|
multiset contains: 2 16 77
|
Complexity
Logarithmic in size.
Iterator validity
No changes.
Data races
The container is accessed (neither the const nor the non-const versions modify the container).
Concurrently accessing the elements of a multiset is safe.
Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the container.