std::unorde...emplace_hint(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… 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