std::multimap::equal_range(3)
π std::multimap::equal_range π
okay bestie, welcome to the std::multimap::equal_range(3) page β it's from the C++ Standard Libary (that spelling is what the source says, iykyk), and we're about to make this range-finding function make sense. no cap, it's lowkey one of the most useful little moves in std::multimap. π¦
π NAME π
std::multimap::equal_range - std::multimap::equal_range
β¨ Synopsis β¨
std::pair<iterator, iterator> equal_range( const Key& key ); (1)
std::pair<const_iterator, const_iterator> equal_range( const Key& key ) const; (2)
template< class K >
std::pair<iterator, iterator> equal_range( const K& x ); (3) (since C++14)
template< class K >
std::pair<const_iterator, const_iterator> equal_range( const K& x ) const; (4) (since C++14)
πΈ Description πΈ
okay so this function returns a range containing all the elements with the given key in the container. The range is defined by two iterators: one points to the first element that is not less than key, and the other points to the first element greater than key. Alternatively, bestie, the first iterator may be obtained with lower_bound(), and the second with upper_bound(). periodt. β¨
- (1), (2) β compares the keys to
key. - (3), (4) β compares the keys to the value
x. This overload participates in overload resolution only if the qualified-idCompare::is_transparentis valid and denotes a type. It allows calling this function without constructing an instance ofKey. π
π Parameters π
keyβ key value to compare the elements to.xβ alternative value that can be compared toKey.
π«Ά Return value π«Ά
std::pair containing a pair of iterators defining the wanted range: the first pointing to the first element that is not less than key, and the second pointing to the first element greater than key.
If there are no elements not less than key, past-the-end (see end()) iterator is returned as the first element. Similarly if there are no elements greater than key, past-the-end iterator is returned as the second element. π
since C++11: sinceemplaceand unhintedinsertalways insert at the upper bound, the order of equivalent elements in the equal range is the order of insertion unless hintedinsertoremplace_hintwas used to insert an element at a different position. π
β‘ Complexity β‘
Logarithmic in the size of the container. π§
π Notes π
Feature-test macro check, bestie:
- Feature-test macro:
__cpp_lib_generic_associative_lookup - Value:
201304L - Std:
(C++14) - Feature: Heterogeneous comparison lookup in associative containers, for overloads
(3,4)
That's the whole table energy, no cap. π
π» Example π»
// Run this code
#include <iostream>
#include <map>
int main()
{
std::multimap<int, char> dict
{
{1, 'A'},
{2, 'B'},
{2, 'C'},
{2, 'D'},
{4, 'E'},
{3, 'F'}
};
auto range = dict.equal_range(2);
for (auto i = range.first; i != range.second; ++i)
std::cout << i->first << ": " << i->second << '\n';
}
π Output: π
2: B
2: C
2: D
π See also π
findβ finds element with specific key (public member function)containsβ checks if the container contains element with specific key(C++20)(public member function)countβ returns the number of elements matching specific key (public member function)upper_boundβ returns an iterator to the first element greater than the given key (public member function)lower_boundβ returns an iterator to the first element not less than the given key (public member function)equal_rangeβ returns range of elements matching a specific key (function template)
that's the whole page, bestie. shoutout to the source http://cppreference.com, dated 2024.06.10, for this std::multimap::equal_range(3) page. now go find your range and slay. πβ¨π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms