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

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

bestie, welcome to the std::experi...ranges::swap(3) page from the C++ Standard Libary manual β€” yes, that’s the header’s spelling, and we’re rolling with it πŸ’€πŸ’–

πŸ’– NAME πŸ’–

std::experimental::ranges::swap β€” std::experimental::ranges::swap. That’s the name, bestie. Full government name. No cap.

✨ Synopsis ✨

okay so this lives in the header, and it’s giving customization point object main character energy:

          Defined in header <experimental/ranges/utility>
          namespace {

              constexpr /* unspecified */ swap = /* unspecified   (ranges TS)
          */;
       (customization point object)

          }
          Call signature
          template< class T, class U >

              requires /* see below */

          void swap( T&& t, U&& u ) noexcept(/* see below */);

ranges::swap exchanges the values referenced by t and u πŸ’…

A call to ranges::swap is equivalent to:

  1. (void)swap(std::forward<T>(t), std::forward<U>(u)), if that expression is valid, where the overload resolution is performed with the following candidates:
    • template<class T> void swap(T&, T&) = delete;
    • template<class T, std::size_t N> void swap(T(&)[N], T(&)[N]) = delete;
    • any declarations of swap found by argument-dependent lookup.

If the function selected by overload resolution does not exchange the values referenced by t and u, the program is ill-formed; no diagnostic required.

  1. Otherwise, (void)ranges::swap_ranges(t, u), if T and U are lvalue references to array types of equal extent (but possibly different element types) and ranges::swap(*t, *u) is a valid expression.
  2. Otherwise, if T and U are both V& for some type V that meets the syntactic requirements of MoveConstructible<V> and Assignable<V&, V>, exchanges the referenced values as if by V v{std::move(t)}; t = std::move(u); u = std::move(v);. If the semantic requirements of either concept are not satisfied, the program is ill-formed; no diagnostic required.
  3. In all other cases, a call to ranges::swap is ill-formed.

ranges::swap can be used in a constant expression if every function it calls (as specified above) can be so used. lowkey iconic ✨

😭 Exceptions 😭

the noexcept tea changes depending on which branch you landed in:

  1. noexcept specification:
noexcept(noexcept((void)swap(std::forward<T>(t),
       std::forward<T>(u))))

where swap is found as described above.

  1. noexcept specification:
noexcept(noexcept(ranges::swap(*t, *u)))
  1. noexcept specification:
noexcept(std::is_nothrow_move_constructible<V>::value &&
         std::is_nothrow_move_assignable<V>::value)

πŸ™ˆ Example πŸ™ˆ

this section is literally incomplete, and the reason is right there:

This section is incomplete
Reason: no example

so yeah, no example here, bestie 😭

πŸ¦‹ See also πŸ¦‹

  • swap β€” swaps the values of two objects (function template)

πŸŽ€ Categories πŸŽ€

  • conditionally noexcept
  • Todo no example

source: http://cppreference.com Β· version/date: 2024.06.10 β€” mwah πŸ’‹ bye bestie 🫢

πŸ“¦ where this page comes from