Defined in header <type_traits> | ||
---|---|---|
template< class T, class U > struct is_swappable_with; | (1) | (since C++17) |
template< class T > struct is_swappable; | (2) | (since C++17) |
template< class T, class U > struct is_nothrow_swappable_with; | (3) | (since C++17) |
template< class T > struct is_nothrow_swappable; | (4) | (since C++17) |
swap(std::declval<T>(), std::declval<U>())
and swap(std::declval<U>(), std::declval<T>())
are both well-formed in unevaluated context after using std::swap;
(see Swappable
), provides the member constant value
equal true
. Otherwise, value
is false
. Access checks are performed as if from a context unrelated to either type. T
is not a referenceable type (i.e., possibly cv-qualified void
or a function type with a cv-qualifier-seq or a ref-qualifier), provides a member constant value
equal to false
. Otherwise, provides a member constant value
equal to std::is_swappable_with<T&, T&>::value
is_nothrow_swappable_with
.T
and U
shall each be a complete type, (possibly cv-qualified) void
, or an array of unknown bound. Otherwise, the behavior is undefined.
template <class T, class U> inline constexpr bool is_swappable_with_v = is_swappable_with<T, U>::value; | (since C++17) | |
template <class T> inline constexpr bool is_swappable_v = is_swappable<T>::value; | (since C++17) | |
template <class T, class U> inline constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<T, U>::value; | (since C++17) | |
template <class T> inline constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<T>::value; | (since C++17) |
value
[static] | true if T is swappable with U , false otherwise (public static member constant) |
operator bool | converts the object to bool , returns value (public member function) |
operator()
(C++14) | returns value (public member function) |
Type | Definition |
---|---|
value_type | bool |
type | std::integral_constant<bool, value> |
This trait does not check anything outside the immediate context of the swap expressions: if the use of T
or U
would trigger template specializations, generation of implicitly-defined special member functions etc, and those have errors, the actual swap may not compile even if std::is_swappable_with<T,U>::value
compiles and evaluates to true
.
swaps the values of two objects (function template) |
|
(C++11)(C++11)(C++11) | checks if a type has a move assignment operator (class template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/types/is_swappable