std::Swappable, std::SwappableWith
| Defined in header <concepts>
|
||
| template< class T > concept Swappable = std::is_swappable_v<T>; |
(1) | (since C++20) |
| template< class T, class U > concept SwappableWith = |
(2) | (since C++20) |
The concept Swappable<T> specifies that lvalues of type T are swappable. The concept SwappableWith<T, U> specifies that expressions of the type and value category encoded by T and U are swappable with each other.
In each case, overload resolution for the call to swap is performed on a candidate set that includes:
- the two std::swap function templates defined in <utility>; and
- any candidates found by argument-dependent lookup.
These concepts are satisfied only if the call to swap actually exchanges the values of its operands. Formally, given
-
a1,a2,b1andb2, distinct objects of typeTsuch thata1is equal toa2andb1is equal tob2,
-
Swappable<T> is satisfied only if, after evaluating either swap(a1, b1) or swap(b1, a1), a1 is equal to b2 and b1 is equal to a2.
And given
-
t1andt2, distinct equal objects of type std::remove_cvref_t<T>, -
u1andu2, distinct equal objects of type std::remove_cvref_t<U>, -
e_t, an expression denotingt1such that decltype((e_t)) isT, -
e_u, an expression denotingu1such that decltype((e_u)) isU, -
C, the common reference type of const std::remove_reference_t<T>& and const std::remove_reference_t<U>&,
-
SwappableWith<T, U> is satisfied only if, after evaluating either swap(e_t, e_u) or swap(e_u, e_t), C(t1) is equal to C(u2) and C(u1) is equal to C(t2).
Notes
These definitions of Swappable and SwappableWith are expected to be temporary, and will be replaced if the full Ranges proposal is adopted for C++20.