swap(std::expected)(3)

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

πŸ’– swap(std::expected) πŸ’–

okay so this is the C++ Standard Libary manual page for swap(std::expected) β€” yes bestie, that’s the manual name, and we’re getting into it πŸ’…


✨ NAME ✨

swap(std::expected) β€” swap(std::expected). That’s the name, that’s the vibe, and honestly? Slay.


πŸ¦‹ Synopsis πŸ¦‹

friend constexpr void swap( expected& lhs, expected& rhs )
(since C++23)
noexcept(/*see below*/);

So it overloads the std::swap algorithm for std::expected. It exchanges the state of lhs with that of rhs. Effectively calls lhs.swap(rhs). ✨

This overload participates in overload resolution only if lhs.swap(rhs) is valid. No cap.

This function is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::expected<T, E> is an associated class of the arguments. iykyk 🫢


🌸 Parameters 🌸

  • lhs, rhs β€” expected objects whose states to swap. Two besties, one state exchange πŸ’–

πŸŽ€ Return value πŸŽ€

(none) β€” literally nothing comes back, bestie. The swap happens in place. 🫢


🫢 Exceptions 🫢

the noexcept specification is:

noexcept(noexcept(lhs.swap(rhs)))

and that’s the whole exception situation, periodt.


πŸ¦‹ Example πŸ¦‹

This section is incomplete 🫠 Reason: no example

πŸ”₯ See also πŸ”₯

  • swap β€” exchanges the contents; it’s a public member function. Iconic behavior tbh πŸ’…

πŸ‘‘ Categories πŸ‘‘

  • conditionally noexcept
  • Todo no example

source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: swap(std::expected)(3) β€” mwah πŸ’‹

πŸ“¦ where this page comes from