The map::equal_range() is a built-in function in C++ STL which returns a pair of iterators. The pair refers to the bounds of a range that includes all the elements in the container which have a key equivalent to k. Since the map container only contains unique key, hence the first iterator in the pair returned thus points to the element and the second iterator in the pair points to the next key which comes after key K. If there are no matches with key K, the range returned is of length 1 with both iterators pointing to the an element which has a key denoting the size of map and elements as 0.
Parameters: This function accepts a single mandatory parameter key which specifies the element whose range in the container is to be returned.
Return Value: The function returns a pair of iterators as explained above.
Below programs illustrate the above method:
The lower bound is 1:40 The upper bound is 4:30
The lower bound is 3:0 The upper bound is 3:0
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- map::at() and map::swap() in C++ STL
- Searching in a map using std::map functions in C++
- Descending order in Map and Multimap of C++ STL
- Map in C++ Standard Template Library (STL)
- Hash Table vs STL Map
- Map of pairs in STL
- Traversing a map (or unordered_map) in C++ STL
- map::clear() in C++ STL
- map::size() in C++ STL
- map::begin() and end() in C++ STL
- map::empty() in C++ STL
- map::operator in C++ STL
- map::at() in C++ STL
- Default values in a Map in C++ STL
- set vs map in C++ STL
- map emplace() in C++ STL
- map cbegin() and cend() function in C++ STL
- map crbegin() and crend() function in C++ STL
- map max_size() in C++ STL
- map upper_bound() function in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : aryanrawlani007