std::swappa...ppable_with(3)

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

πŸ’– std::swappa...ppable_with(3) β€” C++ Standard Libary πŸ’–

okay bestie, this is the std::swappa...ppable_with(3) page from the C++ Standard Libary manual, and it's giving C++20 concepts but make it fashion. no cap, it's short and iconic. πŸ’…

πŸŽ€ NAME πŸŽ€

std::swappable,std::swappable_with - std::swappable,std::swappable_with

✨ Synopsis ✨

Defined in header <concepts>.

          template< class T >

          concept swappable =
              requires(T& a, T& b) {                                    (1)
       (since C++20)
                  ranges::swap(a, b);

              };
          template< class T, class U >

          concept swappable_with =
              std::common_reference_with<T, U> &&
              requires(T&& t, U&& u) {
                  ranges::swap(std::forward<T>(t), std::forward<T>(t)); (2)
       (since C++20)
                  ranges::swap(std::forward<U>(u), std::forward<U>(u));
                  ranges::swap(std::forward<T>(t), std::forward<U>(u));
                  ranges::swap(std::forward<U>(u), std::forward<T>(t));

              };

So swappable<T> is the concept that says: lvalues of type T are swappable. periodt. It's checking that ranges::swap(a, b) works for T& a, T& b. 🫢

And swappable_with<T, U> is a little more entangle-y: it specifies that expressions of the type and value category encoded by T and U are swappable with each other. It is satisfied only if a call to ranges::swap(t, u) exchanges the value of t and u β€” that is, given distinct objects t2 equal to t and u2 equal to u, after evaluating either ranges::swap(t, u) or ranges::swap(u, t), t2 is equal to u and u2 is equal to t. That's the whole vibe check, bestie. ✨

🧚 Equality preservation 🧚

Expressions declared in requires expressions of the standard library concepts are required to be equality-preserving (except where stated otherwise). No cap, that's the rule. πŸ’œ


byeee bestie, this cutie came from http://cppreference.com, the date/version energy is 2024.06.10, and the footer title is std::swappa...ppable_with(3) πŸ’…πŸ«Ά

πŸ“¦ where this page comes from