• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function template
    <iterator>

    std::operator<=

    namespace std {
      template <class Iterator1, class Iterator2>
      bool operator<=(const move_iterator<Iterator1>& x,
                      const move_iterator<Iterator2>& y);           // C++11
    
      template <class Iterator1, class Iterator2>
      constexpr bool operator<=(const move_iterator<Iterator1>& x,
                                const move_iterator<Iterator2>& y); // C++17
    }
    

    概要

    2つのmove_iteratorオブジェクトにおいて、左辺が右辺以下かを判定する。

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

    y.base() < x.base()が有効であり、戻り値boolに変換可能であること。

    戻り値

    return !(y < x);

    #include <iostream>
    #include <vector>
    #include <memory>
    #include <iterator>
    
    int main()
    {
      std::vector<std::unique_ptr<int>> v;
      for (int i = 0; i < 5; ++i)
        v.emplace_back(new int(i));
    
      auto it1 = std::make_move_iterator(v.begin());
      auto it2 = std::make_move_iterator(v.begin() + 1);
    
      if (it1 <= it2) {
        std::cout << "less" << std::endl;
      }
      else {
        std::cout << "not less" << std::endl;
      }
    }
    

    出力

    less
    

    バージョン

    言語

    • C++11

    処理系

    参照