std::experi...al::emplace(3)

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

πŸ’… NAME πŸ’…

bestie, welcome to the std::experi...al::emplace page from the C++ Standard Libary manual πŸ’– this is your group-chat crash course, and yes we are keeping every detail.

std::experimental::optional::emplace β€” std::experimental::optional::emplace


✨ Synopsis ✨

okay so here are the two overloads, and they are giving β€œin-place construction” energy:

template< class... Args >                                  (library
fundamentals TS)
void emplace( Args&&... args );
template< class U, class... Args >
void emplace( std::initializer_list<U> ilist, Args&&...    (library
fundamentals TS)
args );

So the vibe is: this constructs the contained value in-place. If *this already contains a value before the call, that contained value is destroyed by calling its destructor. no cap, it really said that.

  1. Initializes the contained value by direct-initializing (but not direct-list-initializing) with std::forward<Args>(args)... as parameters.
  2. Initializes the contained value by calling its constructor with ilist, std::forward<Args>(args)... as parameters. This overload participates in overload resolution only if std::is_constructible<T, std::initializer_list<U>&, Args&&...>::value is true.

🌸 Parameters 🌸

  • args... β€” the arguments to pass to the constructor
  • ilist β€” the initializer list to pass to the constructor

πŸ¦‹ Type requirements πŸ¦‹

  • T must be constructible from Args...
  • T must be constructible from std::initializer_list and Args...

πŸŽ€ Return value πŸŽ€

(none) β€” literally nothing, bestie. it's giving void energy πŸ’…


πŸ’€ Exceptions πŸ’€

Any exception thrown by the selected constructor of T. If an exception is thrown, *this does not contain a value after this call β€” and the previously contained value, if any, had been destroyed.

🫢 this is the important part: if it throws, the old value is already gone. not a drill.

πŸ‘‘ See also πŸ‘‘

  • operator= β€” assigns contents (public member function)

πŸ“ Category πŸ“

  • * Noindexed pages

okay bye bestie, that’s the whole page β€” source/version: http://cppreference.com, date: 2024.06.10, page: std::experi...al::emplace(3). mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from