I found out that, contrary to my expectation and the documentation, the MSVC's std::unordered_map and std::unordered_multimap (and the unordered sets, too) provide lower_bound and upper_bound.
What do these member functions do? Is there any documentation?
I tried with MSVC 2019 and 2022 in C++20 mode; the following seems to compile:
#include <iostream>
#include <unordered_map>
int main() {
std::unordered_map<int, int> m;
m.emplace(1, 1);
std::cout << m.lower_bound(1)->first;
}
It's a non-standard extension for compatibility purposes only. It is deprecated and has the following warning:
The hash_meow and unordered_meow containers' non-Standard lower_bound() member was provided for interface compatibility with the ordered associative containers, and doesn't match the semantics of the hash_meow or unordered_meow containers. Please use the find() member instead. You can define _SILENCE_STDEXT_HASH_LOWER_BOUND_DEPRECATION_WARNING to suppress this warning.
From yvals_core.h (upper_bound has a similar warning).
Your code actually doesn't compile for me, on VS 17.5 using /std:c++20, as I get the above "warning" (which is actually an error for me).
As to what it actually does, lower_bound is the same as calling find; upper_bound is a bit more complex, but still tries to find the next element after the key, using _Find_last (internal MS function for hash-type objects)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With