std::experimental::ranges::swap - cppreference.com (original) (raw)
| Defined in header <experimental/ranges/utility> | | | | -------------------------------------------------------------------------------------------------------------------------------------------- | | ---------------------------------------- | | namespace { constexpr /* unspecified */ swap = /* unspecified */; } | | (ranges TS) (customization point object) | | Call signature | | | | template< class T, class U > requires /* see below */ 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:
If the function selected by overload resolution does not exchange the values referenced by t and u, the program is ill-formed; no diagnostic required.
Otherwise, (void)ranges::swap_ranges(t, u), if
TandUare lvalue references to array types of equal extent (but possibly different element types) and ranges::swap(*t, *u) is a valid expression.Otherwise, if
TandUare bothV&for some typeVthat 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.In all other cases, a call to
ranges::swapis ill-formed.
ranges::swap can be used in a constant expression if every function it calls (as specified above) can be so used.
[edit] 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 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 ranges::Invocable<const SwapT, Args...>. Otherwise, no function call operator of SwapT participates in overload resolution.
In every translation unit in which ranges::swap is defined, it refers to the same instance of the customization point object. (This means that it can be used freely in things like inline functions and function templates without violating the one-definition rule.)
[edit] Exceptions
, where swap is found as described above.
[edit] Example
[edit] See also
| | swaps the values of two objects (function template) [edit] | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |