operator==,!=,<,<=,>,>=,<=>(std::reverse_iterator)
來自 cppreference.com
定義於標頭檔案 <iterator> |
||
template< class Iter1, class Iter2 > bool operator==( const std::reverse_iterator<Iter1>& lhs, |
(1) | (自 C++17 起為 constexpr) |
template< class Iter1, class Iter2 > bool operator!=( const std::reverse_iterator<Iter1>& lhs, |
(2) | (自 C++17 起為 constexpr) |
template< class Iter1, class Iter2 > bool operator< ( const std::reverse_iterator<Iter1>& lhs, |
(3) | (自 C++17 起為 constexpr) |
template< class Iter1, class Iter2 > bool operator<=( const std::reverse_iterator<Iter1>& lhs, |
(4) | (自 C++17 起為 constexpr) |
template< class Iter1, class Iter2 > bool operator> ( const std::reverse_iterator<Iter1>& lhs, |
(5) | (自 C++17 起為 constexpr) |
template< class Iter1, class Iter2 > bool operator>=( const std::reverse_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 才參與過載決議。
2) 僅若 lhs.base() != rhs.base() 擁有良好形式且可轉換為 bool 才參與過載決議。
3) 僅若 lhs.base() > rhs.base() 擁有良好形式且可轉換為 bool 才參與過載決議。
4) 僅若 lhs.base() >= rhs.base() 擁有良好形式且可轉換為 bool 才參與過載決議。
5) 僅若 lhs.base() < rhs.base() 擁有良好形式且可轉換為 bool 才參與過載決議。
6) 僅若 lhs.base() <= rhs.base() 擁有良好形式且可轉換為 bool 才參與過載決議。
|
(C++20 起) |
目錄 |
[編輯] 引數
lhs, rhs | - | 要比較的迭代器介面卡 |
[編輯] 返回值
1) lhs.base() == rhs.base()
2) lhs.base() != rhs.base()
3) lhs.base() > rhs.base()
4) lhs.base() >= rhs.base()
5) lhs.base() < rhs.base()
6) lhs.base() <= rhs.base()
7) rhs.base() <=> lhs.base()
[編輯] 注意
operator<=> 返回 rhs.base() <=> lhs.base() 而非 lhs.base() <=> rhs.base(),因為這是一個反向迭代器。
[編輯] 示例
執行此程式碼
#include <cassert> #include <iterator> int main() { int a[]{0, 1, 2, 3}; // ↑ └───── x, y // └──────── z // “x” and “y” are equal, but “x” is less than “z” (reversely) std::reverse_iterator<int*> x{std::rend(a) - std::size(a)}, y{std::rend(a) - std::size(a)}, z{std::rbegin(a) + 1}; // 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)); }
[編輯] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
---|---|---|---|
LWG 280 | C++98 | 不允許異類賦值 | 允許 |