template<sentinel_for<Iterator> S>
constexpr bool operator==(const S& s) const;
概要
basic_const_iterator<Iterator>
オブジェクトと別のイテレータ(basic_const_iterator<Iterator>
かIterator
のオブジェクト)が同じ要素を指しているかを判定する。
効果
ラップしているイテレータをcurrent_
メンバ変数に保持するとして、以下と等価
return current_ == s;
戻り値
2つのイテレータが同じ要素を指している場合にtrue
を返す。
備考
この演算子により以下の演算子が使用可能になる。
// !=
template<sentinel_for<Iterator> S>
constexpr bool operator!=(const S&) const;
// 逆順
template<sentinel_for<Iterator> S>
friend constexpr bool operator==(const S&, const basic_const_iterator<Iterator>&);
template<sentinel_for<Iterator> S>
friend constexpr bool operator!=(const S&, const basic_const_iterator<Iterator>&);
例
#include <iostream>
#include <iterator>
#include <vector>
int main() {
std::vector vec = {1, 2, 3, 4, 5};
std::basic_const_iterator cit = vec.begin();
auto se = vec.end();
std::cout << std::boolalpha;
// 元のイテレータとの比較
std::cout << (cit == se) << '\n';
std::cout << (se == cit) << '\n';
std::basic_const_iterator cse = se;
// basic_const_iterator同士の比較
std::cout << (cit == cse) << '\n';
std::cout << (cse == cit) << '\n';
// !=の導出
std::cout << (cit != se) << '\n';
std::cout << (se != cit) << '\n';
std::cout << (cit != cse) << '\n';
std::cout << (cse != cit) << '\n';
}
出力
false
false
false
false
true
true
true
true
バージョン
言語
- C++23
処理系
- Clang: ??
- GCC: 13.1 ✅
- Visual C++: 2022 Update 6 ✅