friend constexpr bool operator==(const iterator& x, const iterator& y) requires equality_comparable<iterator_t<V>>;
概要
自身と別のイテレータが同じ要素を指しているかを判定する。
効果
ラップしているイテレータをcurrent_メンバ変数に保持するとして、以下と等価
return x.current_ == y.current_;
戻り値
元のビューの2つのイテレータが等しい場合にtrueを返す。
備考
- この演算子により
!=演算子が使用可能になる。
例
#include <ranges>
#include <vector>
#include <cassert>
int main()
{
std::vector<int> v = {1, 2, 3, 4, 5};
auto fv = v | std::views::filter([](int i) { return i % 2 == 0; });
auto a = fv.begin();
auto b = fv.begin();
// aとbは同じ要素(2)を指すため等しい
assert(a == b);
++a; // aは次の偶数(4)を指す
assert(a != b);
}
出力
バージョン
言語
- C++20
処理系
- Clang: 13.0.0 ✅
- GCC: 10.1.0 ✅
- ICC: ?
- Visual C++: 2019 Update 10 ✅