liveBook · Manning

Equal_range

As explained in Learn C++ by Example

equal_range is a container member function or standard algorithm that returns the pair of positions delimiting elements equivalent to a specified value.

equal_range finds the range of elements equivalent to a value by returning an std::pair containing lower and upper iterators. The lower iterator points to the first element not less than the value; the upper iterator points to the first element greater than it. section 7.2.2 section 7.2.3

Use the returned bounds to:

  • Detect absence: matching bounds indicate that no equivalent element is present. section 7.2.2
  • Walk every value belonging to a key in an std::multimap. section 7.2.3
  • Replace separate lower_bound and upper_bound calls when searching associative containers. section 7.2.2

Finding overlapping dictionary words

A dictionary lookup can call dictionary.equal_range(stem), then check that the lower iterator is not at the end and that its key begins with the stem. The function returns the first matching word and its offset.

How Learn C++ by Example covers it

How deep it goes
Explains bound semantics, absence detection, iterator traversal, and dictionary use, but does not develop implementation internals.
Examples
Demonstrates sorted-vector bounds, overlapping dictionary words, and repeated-key searches in a multimap.
What it assumes
Assumes familiarity with sorted ranges, iterators, associative containers, and structured bindings.
What you can do after
Apply it via equal_range to locate an associative-container range and iterate matching multimap values.
How it connects
Connects equal_range with lower_bound, upper_bound, iterators, structured bindings, std::map, and std::multimap.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn C++ by Example. The section links point to the parts of the book it draws on.