public member function
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.
Because all elements in a set container are unique, the range returned will contain a single element at most.
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 set 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).
- Value to search for.
Member type value_type is the type of the elements in the container, defined in set as an alias of its first template parameter (T).
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.
int main ()
for (int i=1; i<=5; i++) myset.insert(i*10); // myset: 10 20 30 40 50
ret = myset.equal_range(30);
std::cout << "the lower bound points to: " << *ret.first << '\n';
std::cout << "the upper bound points to: " << *ret.second << '\n';
the lower bound points to: 30
the upper bound points to: 40
Logarithmic in size.
The container is accessed (neither the const nor the non-const versions modify the container).
Concurrently accessing the elements of a set is safe.
Strong guarantee: if an exception is thrown, there are no changes in the container.
- Count elements with a specific value (public member function)
- Return iterator to lower bound (public member function)
- Return iterator to upper bound (public member function)
- Get iterator to element (public member function)