std::flat_m...set::emplace(3)

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

πŸ’… NAME πŸ’…

std::flat_multiset::emplace β€” std::flat_multiset::emplace, bestie. Straight from the C++ Standard Libary manual, and yes, we are keeping the name exactly as it appears. No cap. ✨


🌸 Synopsis 🌸

Okay so here’s the signature, copied exactly because we do not mess with code, periodt:

template< class... Args >            (since C++23)
iterator emplace( Args&&... args );

It inserts a new element into the container, and that element is constructed in-place with the given args. Slay. πŸ’…

First, it initializes an object t of type value_type with std::forward<Args>(args)..., then inserts t as if by:

auto it = ranges::upper_bound(c, t, compare);
c.insert(it, std::move(t));

Overload-resolution vibe check: this overload participates in overload resolution only if std::is_constructible_v<value_type, Args...> is true. Fr fr.

Careful use of emplace allows the new element to be constructed while avoiding unnecessary copy or move operations. That’s the whole point, bestie β€” careful use is the key word. πŸ’–

🧚 Information on iterator invalidation is copied from here.

πŸŽ€ Parameters πŸŽ€

  • args β€” 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. Iconic behavior, honestly. 😭


πŸ”₯ Complexity πŸ”₯

Logarithmic in the size of the container. Not linear, bestie. Log. πŸ’…


🌈 Example 🌈

This section is incomplete.

Reason: no example.

Not me staring at an empty example section πŸ˜­πŸ’€.


πŸ‘‘ See also πŸ‘‘

  • emplace_hint β€” constructs elements in-place using a hint (public member function).
  • insert β€” inserts elements (public member function).

πŸ“ Category πŸ“

  • Todo no example

Sign-off tea: source/version http://cppreference.com, date 2024.06.10, page std::flat_m...set::emplace(3). Bye bestie, go emplace something cute! πŸ’–βœ¨

πŸ“¦ where this page comes from