std::unorde...emplace_hint(3)
π NAME
std::unordered_multiset::emplace_hint β bestie, it's literally std::unordered_multiset::emplace_hint, the C++ standard library icon that it is π (manual name: C++ Standard Libary, no that's not a typo of mine, that's just how the page spells it, iykyk)
β¨ Synopsis
Okay so here's the whole vibe β this is a template, and it's been around (since C++11):
template< class... Args >
iterator emplace_hint( const_iterator hint, Args&&... args );
So what does it do? It inserts a new element into the container, and it uses hint as a suggestion as to where the element should go. A suggestion, bestie β not a demand π«Ά
The constructors of the key and mapped value get called with exactly the same arguments as supplied to the function, forwarded with std::forward<Args>(args).... No extra seasoning, no substitutions β¨
And now the part that actually matters, so pay attention π₯:
- If, after the operation, the new number of elements is greater than old
max_load_factor() * bucket_count(), a rehashing takes place. - If rehashing occurs (because of the insertion), all iterators are invalidated π
- Otherwise (no rehashing), iterators are not invalidated. Slay.
No cap, that iterator invalidation clause is the main character here. Read it twice.
πΈ Parameters
hintβ an iterator, used as a suggestion as to where to insert the new element. It's giving "polite recommendation," not "binding contract" πargsβ the arguments to forward to the constructor of the element π§
β Return value
An iterator to the inserted element. That's it, that's the return value π
π¦ Exceptions
If an exception is thrown for any reason, this function has no effect β that's the strong exception safety guarantee, and honestly? Obsessed. She's safe, she's strong, she's not leaving you with half-inserted chaos ππ
π Complexity
Amortized constant on average. Worst case linear in the size of the container. So like, usually a vibe check passes instantly, but sometimes she has to look at literally everything π
π Example
This section is incomplete.
Reason: no example
Not me showing up to the group chat with a Reason: no example π the docs said "figure it out bestie" π
π See also
emplaceβ constructs element in-place (public member function)insertβ inserts elements or nodes(since C++17)(public member function)
π Category:
- Todo no example
Okay bestie, that's the whole page, hope you ate it up π«Άβ¨ β this was pulled from http://cppreference.com, dated 2024.06.10, and the page header/footer around it all reads std::unorde...emplace_hint(3) because someone at cppreference let the column width win π
mwah, go insert something π
π¦ 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