std::flat_m...:equal_range(3)
πΈ NAME πΈ
okay so bestie, welcome to the std::flat_m...:equal_range(3) page β the manual name is literally std::flat_multimap::equal_range, and the NAME line says std::flat_multimap::equal_range - std::flat_multimap::equal_range. no cap, this is the C++ Standard Library page for your βwhere are all my matching keys at?β moment π
β¨ Synopsis β¨
four overloads, all since C++23, fr fr:
std::pair<iterator, iterator> equal_range( const Key& key );
(1) (since C++23)
std::pair<const_iterator, const_iterator> equal_range( const Key&
(2) (since C++23)
key ) const;
template< class K >
(3) (since C++23)
std::pair<iterator, iterator> equal_range( const K& x );
template< class K >
std::pair<const_iterator, const_iterator> equal_range( const K& x
(4) (since C++23)
) const;
okay so what does it actually do? Returns a range containing all elements with the given key in the container. The range is defined by two iterators, one pointing to the first element that is not less than key and another pointing to the first element greater than key. Alternatively, the first iterator may be obtained with lower_bound(), and the second with upper_bound(). π¦
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-id Compare::is_transparent is valid and denotes a type. It allows calling this function without constructing an instance of Key. iykyk, thatβs the whole point of that overload.
π 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. thatβs the βnothing matched, hereβs the endβ vibe.
Since emplace and unhinted insert always insert at the upper bound, the order of equivalent elements in the equal range is the order of insertion unless hinted insert or emplace_hint was used to insert an element at a different position. so if youβre obsessed with insertion order, this note is your bestie.
π¦ Complexity π¦
Logarithmic in the size of the container. β
π Example π
the example literally says // Run this code π
#include <iostream>
#include <flat_map>
template<typename I>
void print_equal_range(I first, I lb, I ub, I last)
{
for (I i{first}; i != lb; ++i)
std::cout << *i << ' ';
std::cout << "[ ";
for (I i{lb}; i != ub; ++i)
std::cout << *i << ' ';
std::cout << ") ";
for (I i{ub}; i != last; ++i)
std::cout << *i << ' ';
std::cout << '\n';
}
int main()
{
std::flat_multimap<int> c{4, 3, 2, 1, 3, 3};
std::cout << "c = ";
print_equal_range(begin(c), begin(c), end(c), end(c));
for (int key{}; key != 6; ++key)
{
std::cout << "key = " << key << "; equal range = ";
const auto [lb, ub] = c.equal_range(key);
print_equal_range(begin(c), lb, ub, end(c));
}
}
π See also π
findβ finds element with specific key (public member function)containsβ checks if the container contains element with specific key (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)
catch you later, bestie π
β¨ this page came from source http://cppreference.com, version/date 2024.06.10, and itβs the std::flat_m...:equal_range(3) page. periodt. π
π¦ 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