std::multimap::upper_bound(3)
π NAME
std::multimap::upper_bound β no cap, that's literally the whole name, it's giving "I contain myself" energy π
So bestie, you've got a std::multimap, right? And you wanna know where the "bigger than this key" zone starts. That's this girl. She's the boundary-finder, the first-one-past-the-line, the "everything from here on out is greater than your key" icon. Periodt. β¨
πΈ Synopsis
iterator upper_bound( const Key& key ); (1)
const_iterator upper_bound( const Key& key ) const; (2)
template< class K > (3) (since C++14)
iterator upper_bound( const K& x );
template< class K > (4) (since C++14)
const_iterator upper_bound( const K& x ) const;
Okay so there's four flavors, and they are not the same vibe, so pay attention π«Ά
- Overloads 1 and 2 return an iterator pointing to the first element that is greater than key.
- Overloads 3 and 4 (both since C++14) return an iterator pointing to the first element that compares greater to the value x. π¦ Here's the tea though: this overload only participates in overload resolution if the qualified-id
Compare::is_transparentis valid and denotes a type. Why do we care? Because it lets you call this function without constructing an instance ofKey. Chef's kiss. π
π Parameters
keyβ the key value you're comparing the elements against. Your reference point, your "greater than what?" πxβ the alternative value that can be compared toKey. The flexible bestie. π
β Return value
An iterator pointing to the first element that is greater than key. Plain and simple, main character energy.
But listen β if no such element exists? You get the past-the-end iterator (see end()). So like, check before you dereference, bestie, I'm begging ππ
π₯ Complexity
Logarithmic in the size of the container. Fast. Efficient. Ate and left no crumbs. β‘
π§ Notes
Feature-test macro time, write these down, they will be on the quiz ππ
__cpp_lib_generic_associative_lookupβ value201304L, standard (C++14), feature: Heterogeneous comparison lookup in associative containers, for overloads (3,4)
That's the one that unlocks the fancy "compare without building a Key" behavior. Iykyk. β¨
π Example
This section is incomplete.
Reason: no example.
(Yeah, they really left us hanging. Tragic. Not me waiting for a snippet that never comes π)
π See also
equal_rangeβ returns range of elements matching a specific key (public member function)lower_boundβ returns an iterator to the first element not less than the given key (public member function)
Go check out lower_bound too, she's the other half of this whole boundary situation β the two of them together are giving duo goals π«Ά
π Category
- Todo no example
So that's the whole page, bestie β sourced straight from http://cppreference.com, version 2024.06.10, and the page itself is std::multimap::upper_bound(3). Slay, go find your upper bound, and remember: past-the-end is a real place and you don't wanna live there πΈπ
π¦ 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