std::swappa...ppable_with(3)
π 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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms