名稱空間
變體
操作

operator==,!=,<,<=,>,>=,<=>(std::move_iterator)

來自 cppreference.com
 
 
迭代器庫
迭代器概念
迭代器原語
演算法概念與工具
間接可呼叫概念
常用演算法要求
工具
迭代器介面卡
 
 
定義於標頭檔案 <iterator>
template< class Iter1, class Iter2 >

bool operator==( const std::move_iterator<Iter1>& lhs,

                 const std::move_iterator<Iter2>& rhs );
(1) (自 C++17 起為 constexpr)
template< class Iter1, class Iter2 >

bool operator!=( const std::move_iterator<Iter1>& lhs,

                 const std::move_iterator<Iter2>& rhs );
(2) (自 C++17 起為 constexpr)
(C++20 前)
template< class Iter1, class Iter2 >

bool operator< ( const std::move_iterator<Iter1>& lhs,

                 const std::move_iterator<Iter2>& rhs );
(3) (自 C++17 起為 constexpr)
template< class Iter1, class Iter2 >

bool operator<=( const std::move_iterator<Iter1>& lhs,

                 const std::move_iterator<Iter2>& rhs );
(4) (自 C++17 起為 constexpr)
template< class Iter1, class Iter2 >

bool operator> ( const std::move_iterator<Iter1>& lhs,

                 const std::move_iterator<Iter2>& rhs );
(5) (自 C++17 起為 constexpr)
template< class Iter1, class Iter2 >

bool operator>=( const std::move_iterator<Iter1>& lhs,

                 const std::move_iterator<Iter2>& rhs );
(6) (自 C++17 起為 constexpr)
template< class Iter1, std::three_way_comparable_with<Iter1> Iter2 >

constexpr std::compare_three_way_result_t<Iter1, Iter2>
    operator<=>( const std::move_iterator<Iter1>& lhs,

                 const std::move_iterator<Iter2>& rhs );
(7) (C++20 起)

比較 lhsrhs 的底層迭代器。

1) 僅當 lhs.base() == rhs.base() 格式良好且可轉換為 bool 時,此過載才參與過載決議。
3-6) 僅當 lhs.base() < rhs.base() 格式良好且可轉換為 bool 時,這些過載才參與過載決議。

!= 運算子由 operator== 合成

(C++20 起)

目錄

[編輯] 引數

lhs, rhs - 要比較的迭代器介面卡

[編輯] 返回值

1) lhs.base() == rhs.base()
2) !(lhs == rhs)
3) lhs.base() < rhs.base()
4) !(rhs < lhs)
5) rhs < lhs
6) !(lhs < rhs)
7) lhs.base() <=> rhs.base()

[編輯] 示例

#include <cassert>
#include <iterator>
 
int main()
{
    int a[]{9, 8, 7, 6};
    //            │  └───── x, y
    //            └──────── z
 
    // “x” and “y” are equal, but “x” is greater than “z”
    std::move_iterator<int*>
        x{std::end(a) - 1},
        y{std::end(a) - 1},
        z{std::end(a) - 2};
 
    // two-way comparisons
    assert(  x == y );
    assert(!(x != y));
    assert(!(x <  y));
    assert(  x <= y );
    assert(!(x == z));
    assert(  x != z );
    assert(!(x <  z));
    assert(!(x <= z));
 
    // three-way comparisons
    assert(  x <=> y == 0 );
    assert(!(x <=> y <  0));
    assert(!(x <=> y >  0));
    assert(!(x <=> z == 0));
    assert(!(x <=> z <  0));
    assert(  x <=> z >  0 );
}

[編輯] 參閱

比較底層迭代器和底層哨兵
(函式模板) [編輯]