public member function
<unordered_set>

std::unordered_multiset::equal_range

pair<iterator,iterator>
  equal_range ( const key_type& k );
pair<const_iterator,const_iterator>
  equal_range ( const key_type& k ) const;
Get range of elements with specific key
Returns the bounds of a range that includes all the elements in the container that compare equal to k.

If k does not match any element in the container, the range returned has end as both its lower and upper range bounds.

Parameters

k
Value to be compared.
Member type key_type is the type of the elements in the container. In unordered_set containers it is the same as value_type, defined as an alias of the class's first template parameter (Key).

Return value

The function returns a pair, where its member pair::first is an iterator to the lower bound of the range, and pair::second is an iterator to its upper bound. The elements in the range are those between these two iterators, including pair::first, but not pair::second.

Member types iterator and const_iterator are forward iterator types.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// unordered_multiset::equal_range
#include <iostream>
#include <string>
#include <unordered_set>

int main ()
{
  std::unordered_multiset<std::string> myums =
    {"cow","pig","pig","chicken","pig","chicken"};

  auto myrange = myums.equal_range("pig");

  std::cout << "These pigs were found:";

  while ( myrange.first != myrange.second ) {
    std::cout << " " << *myrange.first++;
  }

  std::cout << std::endl;

  return 0;
}


Output:
These pigs were found: pig pig pig

Complexity

Average case: constant.
Worst case: linear in container size.

Iterator validity

No changes.

See also

  • 1793521592 2018-02-23
  • 2864591591 2018-02-23
  • 6167231590 2018-02-23
  • 3669201589 2018-02-23
  • 7946381588 2018-02-23
  • 8957701587 2018-02-23
  • 3891941586 2018-02-23
  • 6039851585 2018-02-23
  • 2573991584 2018-02-23
  • 7728781583 2018-02-23
  • 3731582 2018-02-23
  • 1007451581 2018-02-22
  • 8908121580 2018-02-22
  • 141161579 2018-02-22
  • 9421578 2018-02-22
  • 2826901577 2018-02-22
  • 3647361576 2018-02-22
  • 5717551575 2018-02-22
  • 523811574 2018-02-22
  • 6439871573 2018-02-22