Defined in header <concepts> | ||
---|---|---|
inline namespace /* unspecified */ { inline constexpr /* unspecified */ swap = /* unspecified */; } | (since C++20) (customization point object) | |
Call signature | ||
template< class T, class U > requires /* see below */ constexpr void swap(T&& t, U&& u) noexcept(/* see below */); |
Exchanges the values referenced by t
and u
.
A call to ranges::swap
is equivalent to:
(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;
swap
found by argument-dependent lookup.t
and u
, the program is ill-formed; no diagnostic required.(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;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.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.
The name ranges::swap
denotes a customization point object, which is a function object of a literal Semiregular
class type (denoted, for exposition purposes, as SwapT
). All instances of SwapT
are equal. Thus, ranges::swap
can be copied freely and its copies can be used interchangeably.
Given a set of types Args...
, if std::declval<Args>()...
meet the requirements for arguments to ranges::swap
above, SwapT
will satisfy std::Invocable<const SwapT&, Args...>
. Otherwise, no function call operator of SwapT
participates in overload resolution.
noexcept
specification: noexcept(noexcept((void)swap(std::forward<T>(t), std::forward<T>(u))))
swap
is found as described above.noexcept
specification: noexcept(noexcept(ranges::swap(*t, *u)))
noexcept
specification: noexcept(std::is_nothrow_move_constructible_v<V> &&
std::is_nothrow_move_assignable_v<V>)
(C++20) | specifies that a type can be swapped or that two types can be swapped with each other (concept) |
swaps the values of two objects (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/utility/ranges/swap