• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <iterator>

    std::basic_const_iterator::operator>=

    constexpr bool operator>=(const basic_const_iterator& y) const
      requires random_access_iterator<Iterator>;                                        // (1)
    
    template<different-from<basic_const_iterator> I>
    constexpr bool operator>=(const I& y) const
      requires random_access_iterator<Iterator> && totally_ordered_with<Iterator, I>;   // (2)
    
    template<not-a-const-iterator I>
    friend constexpr bool operator>=(const I& x, const basic_const_iterator& y)
      requires random_access_iterator<Iterator> && totally_ordered_with<Iterator, I>;   // (3) 非メンバ関数
    

    概要

    basic_const_iterator<Iterator>オブジェクト同士あるいは別のイテレータとの間で、左辺が右辺以上かを判定する。

    • (1) : 同じrandom_access_iterator特殊化同士の間の>=比較
    • (2) : Iteratorと比較可能な型の値との間の>=比較
    • (3) : (2)の逆順の演算子

    テンプレートパラメータ制約

    not-a-const-iterator<I>Ibasic_const_iteratorの特殊化ではない場合にtrueとなる説明専用のコンセプトである。

    効果

    ラップしているイテレータをcurrent_メンバ変数に保持するとして、以下と等価

    • (1) : 以下と等価

      return current_ >= y.current_;
      

    • (2) : 以下と等価

      return current_ >= y;
      

    • (3) : 以下と等価

      return x >= y.current_;
      

    備考

    (3)の関数はHidden friendsとして定義される。

    #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::basic_const_iterator cse = se;
    
      std::cout << std::boolalpha;
    
      // basic_const_iterator同士の比較
      std::cout << (cit >= cse) << '\n';
      std::cout << (cse >= cit) << '\n';
      std::cout << (cit >= cit) << '\n';
    
      // 元のイテレータとの比較
      std::cout << (cit >= se) << '\n';
      std::cout << (se >= cit) << '\n';
      std::cout << (cit >= cit.base()) << '\n';
    }
    

    出力

    false
    true
    true
    false
    true
    true
    

    バージョン

    言語

    • C++23

    処理系

    参照