std::ranges::iter_swap - cppreference.com
From cppreference.com
| Defined in header |
||
|
|
(since C++20) (customization point object) |
|
| Call signature |
||
|
|
(since C++20) | |
| Helper function |
||
|
|
(exposition only*) | |
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), ifi1ori2has a class or enumeration type and the expression is well-formed, where the overload resolution ofiter_swapis performed with the additional candidatevoid iter_swap(auto, auto) = delete;[1], excludingstd::ranges::iter_swapitself.- If the selected overload does not exchange the value denoted by
i1andi2, the program is ill-formed, no diagnostic required.
- If the selected overload does not exchange the value denoted by
- Otherwise,
ranges::swap(*i1, *i2)if bothI1andI2modelindirectly_readableand ifstd::iter_reference_t<I1>andstd::iter_reference_t<I2>modelswappable_with. - Otherwise,
(void)(*i1 =iter-exchange-move(i2, i1)), ifstd::indirectly_movable_storable<I1, I2>andstd::indirectly_movable_storable<I2, I1>are both modeled, except thati1is only evaluated once. - Otherwise,
ranges::iter_swap(i1, i2)is ill-formed, which can result in substitution failure whenranges::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.
Example
See also
| swaps the objects pointed to by two adjusted underlying iterators (function template) [edit] | |
| swaps the objects pointed to by two underlying iterators (function template) [edit] | |
| swaps the elements pointed to by two iterators (function template) [edit] |