operator==,!=,<,<=,>,>=,<=>(std::move_iterator)
來自 cppreference.com
定義於標頭檔案 <iterator> |
||
template< class Iter1, class Iter2 > bool operator==( const std::move_iterator<Iter1>& lhs, |
(1) | (自 C++17 起為 constexpr) |
template< class Iter1, class Iter2 > bool operator!=( const std::move_iterator<Iter1>& lhs, |
(2) | (自 C++17 起為 constexpr) (C++20 前) |
template< class Iter1, class Iter2 > bool operator< ( const std::move_iterator<Iter1>& lhs, |
(3) | (自 C++17 起為 constexpr) |
template< class Iter1, class Iter2 > bool operator<=( const std::move_iterator<Iter1>& lhs, |
(4) | (自 C++17 起為 constexpr) |
template< class Iter1, class Iter2 > bool operator> ( const std::move_iterator<Iter1>& lhs, |
(5) | (自 C++17 起為 constexpr) |
template< class Iter1, class Iter2 > bool operator>=( const std::move_iterator<Iter1>& lhs, |
(6) | (自 C++17 起為 constexpr) |
template< class Iter1, std::three_way_comparable_with<Iter1> Iter2 > constexpr std::compare_three_way_result_t<Iter1, Iter2> |
(7) | (C++20 起) |
比較 lhs 和 rhs 的底層迭代器。
1) 僅當 lhs.base() == rhs.base() 格式良好且可轉換為 bool 時,此過載才參與過載決議。
3-6) 僅當 lhs.base() < rhs.base() 格式良好且可轉換為 bool 時,這些過載才參與過載決議。
|
(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 ); }
[編輯] 參閱
比較底層迭代器和底層哨兵 (函式模板) |