std::flat_set::emplace(3)

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

✨ std::flat_set::emplace ✨

okay so bestie, welcome to std::flat_set::emplace(3) from the C++ Standard Libary manual β€” yes, the manual name is folded in right here, cute and accounted for. this is the group chat for inserting one (1) element into a std::flat_set, and it's giving iconic container energy. πŸ’–

🌸 NAME 🌸

std::flat_set::emplace β€” literally std::flat_set::emplace. that's the name, bestie, no cap. πŸŽ€

✨ Synopsis ✨

template< class... Args >                             (since C++23)
std::pair<iterator, bool> emplace( Args&&... args );

Inserts a new element into the container constructed in-place with the given args, if there is no element with the key in the container. slay. ✨

First, 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));

This overload participates in overload resolution only if std::is_constructible_v<value_type, Args...> is true. that's the vibe check for this overload, periodt. πŸ’…

Careful use of emplace allows the new element to be constructed while avoiding unnecessary copy or move operations. highkey the whole point. 🫢

Information on iterator invalidation is copied from here β€” yes, that's the actual tea, copied from there. πŸ¦‹

πŸ’– Parameters πŸ’–

  • args β€” arguments to forward to the constructor of the element.

🌟 Return value 🌟

A pair consisting of an iterator to the inserted element (or to the element that prevented the insertion) and a bool value set to true if and only if the insertion took place. so: iterator + yes/no, bestie. βœ…

πŸ”₯ Exceptions πŸ”₯

If an exception is thrown for any reason, this function has no effect (strong exception safety guarantee). dramatic? yes. but also safe? also yes. 😭

🧚 Complexity 🧚

Logarithmic in the size of the container. log-time, no cap. πŸ“ˆ

😭 Example 😭

This section is incomplete. Reason: no example. the example slot is literally empty, and we're all just gonna have to deal. πŸ’€

πŸ‘‘ See also πŸ‘‘

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

🏷️ Category 🏷️

  • Todo no example

signed off with love by cppreference.com, dated 2024.06.10, for std::flat_set::emplace(3) β€” mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from