std::experi...tional::swap(3)

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

πŸ’– std::experi...tional::swap(3) β€” from the C++ Standard Libary πŸ’–

okay so bestie, welcome to the std::experi...tional::swap(3) page. Manual name? C++ Standard Libary (yes, that’s spelled exactly like that). This is the std::experimental::optional::swap glow-up, and we’re gonna get through every little detail together 🫢✨

🌸 NAME 🌸

std::experimental::optional::swap - std::experimental::optional::swap β€” okay so that’s the whole NAME line, bestie; same name twice, no notes πŸ’…

πŸ¦‹ Synopsis πŸ¦‹

void swap( optional& other ) noexcept(/* see below */);  (library
fundamentals TS)

Swaps the contents with those of other. That’s the whole main-character move.

  • If neither *this nor other contain a value, the function has no effect. literally nothing happens, and that’s valid πŸ’€
  • If only one of *this and other contains a value (let’s call this object in and the other un), the contained value of un is direct-initialized from std::move(*in), followed by destruction of the contained value of in as if by in.val->T::~T(). After this call, in does not contain a value, and un contains a value. slay, the value moved houses 🏠✨
  • If both *this and other contain values, the contained values are exchanged by calling using std::swap; swap(**this, *other). The T lvalues must satisfy Swappable. no cap, that’s the requirement.

πŸŽ€ Parameters πŸŽ€

  • other β€” the optional object to exchange the contents with.

⭐ Return value ⭐

(none) β€” nothing is returned, bestie.

πŸ”₯ Exceptions πŸ”₯

noexcept specification:

          noexcept(std::is_nothrow_move_constructible<T>::value &&
                     noexcept(swap(std::declval<T&>(), std::declval<T&>())))

In the case of a thrown exception, the states of the contained values of *this and other are determined by the exception safety guarantees of swap of type T or T's move constructor, whichever is called. For both *this and other, if the object contained a value, it is left containing a value, and the other way round. important caveat, bestie β€” read it twice if you need πŸ’…

πŸ” See also πŸ”

  • std::swap(std::experimental::optional) β€” specializes the std::swap algorithm (function).

🏷️ Categories 🏷️

  • Noindexed pages
  • conditionally noexcept

mwah πŸ’‹ β€” source/version/date: http://cppreference.com, 2024.06.10. that’s the whole page, bestie πŸ«ΆπŸ’–

πŸ“¦ where this page comes from