std::ranges::iter_swap(3)
π std::ranges::iter_swap(3) π
okay bestie, welcome to the std::ranges::iter_swap(3) page from the C++ Standard Libary manual β¨ this one is giving template-wizard energy, and weβre gonna keep every single detail, no cap π
πΈ NAME πΈ
std::ranges::iter_swap β std::ranges::iter_swap
β¨ Synopsis β¨
Itβs defined in the header <iterator>, and hereβs the synopsis tea exactly as the page serves it β yes, the formatting is a little chaotic, but we keep it 100 π
Defined in header <iterator>
namespace ranges {
inline namespace /* unspecified */ {
(since C++20)
inline constexpr /* unspecified */
(customization
iter_swap = /* unspecified */;
point object)
}
}
π« Call signature π«
template< class I1, class I2 >
constexpr void iter_swap( I1&& i1, I2&& i2 ) noexcept(/* see below
(since C++20)
*/);
π§ Helper function π§
template< class X, class Y >
constexpr std::iter_value_t<X>
iter-exchange-move( X&& x, Y&& y )
(exposition
only*)
noexcept(noexcept(std::iter_value_t<X>(std::ranges::iter_move(x)))
&&
noexcept(*x = std::ranges::iter_move(y)));
It 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.
^[1] β 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. For exposition purposes, the cv-unqualified version of its type is denoted as __iter_swap_fn.
All instances of __iter_swap_fn are equal. The effects of invoking different instances of type __iter_swap_fn on the same arguments are equivalent, regardless of whether the expression denoting the instance is an lvalue or rvalue, and is const-qualified or not (however, a volatile-qualified instance is not required to be invocable). Thus, ranges::iter_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::iter_swap above, __iter_swap_fn models
std::invocable<__iter_swap_fn, Args...>,std::invocable<const __iter_swap_fn, Args...>,std::invocable<__iter_swap_fn&, Args...>, andstd::invocable<const __iter_swap_fn&, Args...>.
Otherwise, no function call operator of __iter_swap_fn participates in overload resolution.
π Example π
This section is incomplete Reason: no example
π See also π
iter_swapswaps the objects pointed to by two adjusted underlying iterators (C++20) (function template)iter_swapswaps the objects pointed to by two underlying iterators (C++20) (function template)iter_swapswaps the elements pointed to by two iterators (function template)
π Category π
- Todo no example
mwah π source/version is http://cppreference.com, date is 2024.06.10, and this iconic page is std::ranges::iter_swap(3). bye bestie π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms