iter_swap(std::counted_iterator)
From cppreference.com
< cpp | iterator | counted iterator
| template< std::indirectly_swappable<I> I2 > friend constexpr void |
(C++20以降) | |
2つの基底イテレータが指すオブジェクトを交換します。 x.count() または y.count() のどちらかが 0 と等しい場合、動作は未定義です。
関数本体は、次のコードと等価です: ranges::iter_swap(x.base(), y.base());。
この関数テンプレートは、通常の 非修飾 lookup または 修飾 lookup では見えず、 std::counted_iterator<I> が引数に関連付けられたクラスである場合にのみ、 引数依存 lookup によって見つけることができます。
目次 |
[編集] パラメータ
| x, y | - | 交換する要素のイテレータアダプタ |
[編集] 戻り値
(なし)
[編集] 計算量
定数。
[編集] 例
このコードを実行
#include <iostream> #include <iterator> #include <list> #include <vector> int main() { std::vector p{1, 2, 3, 4}, q{5, 6, 7, 8}; std::counted_iterator<std::vector<int>::iterator> ip{p.begin(), 2}; std::counted_iterator<std::vector<int>::iterator> iq{q.begin(), 3}; std::cout << *ip << ' ' << *iq << '\n'; iter_swap(ip, iq); // ADL std::cout << *ip << ' ' << *iq << '\n'; std::list x{0, 1, 3}; std::counted_iterator<std::list<int>::iterator> ix{x.begin(), 2}; // iter_swap(ip, ix); // error: not indirectly swappable }
出力
1 5 5 1
[編集] 関連項目
| 2つのオブジェクトの値を交換する (関数テンプレート) | |
| 2つの要素の範囲を交換する (関数テンプレート) | |
| 2つのイテレータが指す要素をスワップする (関数テンプレート) | |
| (C++20) |
2つの間接参照可能なオブジェクトが参照する値を交換する (カスタマイゼーションポイントオブジェクト) |
| (C++20) |
基底イテレータの間接参照の結果を関連する右辺値参照型にキャストする (関数) |