std::ranges::swap
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 */ |
||
Exchanges the values referenced by t
and u
.
A call to ranges::swap
is expression-equivalent to:
- template<class T> void swap(T&, T&) = delete;
- template<class T, std::size_t N> void swap(T(&)[N], T(&)[N]) = delete;
- any declarations of
swap
found by argument-dependent lookup.
t
and u
, the program is ill-formed; no diagnostic required.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 std::move_constructible<V> and std::assignable_from<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, which can result in substitution failure when ranges::swap(t, u) appears in the immediate context of a template instantiation.Expression-equivalent
Expression e is expression-equivalent to expression f, if e and f have the same effects, either are both potentially-throwing or are both not potentially-throwing (i.e. noexcept(e) == noexcept(f)), and either are both constant subexpressions or are both not constant subexpressions.
Customization point objects
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 swap_ftor
). All instances of swap_ftor
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, swap_ftor
will satisfy std::invocable<const swap_ftor&, Args...>. Otherwise, no function call operator of swap_ftor
participates in overload resolution.
Example
This section is incomplete Reason: no example |
See also
(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) |