std::ranges::iter_swap
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Iterator library
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)(C++20)(C++23)(C++20)(C++20)
(deprecated in C++17)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++14)
(C++11)
(C++11)
(C++20)(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++23)
(C++23)
(C++23)
(C++23)
(C++23)
(C++11)(C++14)
(C++14)(C++14)
Defined in header
<iterator>
namespace ranges {
(since C++20) inline namespace /* unspecified */ {
inline constexpr /* unspecified */
iter_swap = /* unspecified */;
}
(customization point object)
Call signature
template< class I1, class I2 >
constexpr void iter_swap( I1&& i1, I2&& i2 ) noexcept(/* see below */);
(since C++20)
constexpr void iter_swap( I1&& i1, I2&& i2 ) noexcept(/* see below */);
Helper function
template< class X, class Y >
(exposition only*)
constexpr std::iter_value_t <X>
iter-exchange-move( X&& x, Y&& y )
noexcept(noexcept(std::iter_value_t <X>(std::ranges::iter_move (x))) &&
Swaps values denoted by two iterators.
The effect of the exposition-only helper function iter-exchange-move
is equivalent to
std::iter_value_t <X> old(std::ranges::iter_move (x)); *x = std::ranges::iter_move (y); return old;
ranges::iter_swap(i1, i2) is expression-equivalent to:
- (void)iter_swap(i1, i2), if i1 or i2 has a class or enumeration type and the expression is well-formed, where the overload resolution of
iter_swap
is performed with the additional candidate void iter_swap(auto, auto) = delete;[1] , excludingstd::ranges::iter_swap
itself.- If the selected overload does not exchange the value denoted by i1 and i2, the program is ill-formed, no diagnostic required.
- Otherwise, ranges::swap (*i1, *i2) if both
I1
andI2
modelindirectly_readable
and if std::iter_reference_t <I1> and std::iter_reference_t <I2> modelswappable_with
. - Otherwise, (void)(*i1 =
iter-exchange-move
(i2, i1)), if std::indirectly_movable_storable <I1, I2> and std::indirectly_movable_storable <I2, I1> are both modeled, except that i1 is only evaluated once. - Otherwise, ranges::iter_swap(i1, i2) is ill-formed, which can result in substitution failure when ranges::iter_swap(i1, i2) appears in the immediate context of a template instantiation.
- ↑ This precludes calling unconstrained std::iter_swap .
Customization point objects
The name ranges::iter_swap
denotes a customization point object, which is a const function object of a literal semiregular
class type. See CustomizationPointObject for details.
[edit] Example
This section is incomplete
Reason: no example
Reason: no example
[edit] See also
(C++20)
(function template) [edit]