operator==,!=,<,<=,>,>=,<=>(std::move_iterator)
(1) | ||
template< class Iterator1, class Iterator2 > bool operator==( const std::move_iterator<Iterator1>& lhs, |
(直到 C++17) | |
template< class Iterator1, class Iterator2 > constexpr bool operator==( const std::move_iterator<Iterator1>& lhs, |
(从 C++17 开始) | |
(2) | ||
template< class Iterator1, class Iterator2 > bool operator!=( const std::move_iterator<Iterator1>& lhs, |
(直到 C++17) | |
template< class Iterator1, class Iterator2 > constexpr bool operator!=( const std::move_iterator<Iterator1>& lhs, |
(从 C++17 开始) (直到 C++20) |
|
(3) | ||
template< class Iterator1, class Iterator2 > bool operator<( const std::move_iterator<Iterator1>& lhs, |
(直到 C++17) | |
template< class Iterator1, class Iterator2 > constexpr bool operator<( const std::move_iterator<Iterator1>& lhs, |
(从 C++17 开始) | |
(4) | ||
template< class Iterator1, class Iterator2 > bool operator<=( const std::move_iterator<Iterator1>& lhs, |
(直到 C++17) | |
template< class Iterator1, class Iterator2 > constexpr bool operator<=( const std::move_iterator<Iterator1>& lhs, |
(从 C++17 开始) | |
(5) | ||
template< class Iterator1, class Iterator2 > bool operator>( const std::move_iterator<Iterator1>& lhs, |
(直到 C++17) | |
template< class Iterator1, class Iterator2 > constexpr bool operator>( const std::move_iterator<Iterator1>& lhs, |
(从 C++17 开始) | |
(6) | ||
template< class Iterator1, class Iterator2 > bool operator>=( const std::move_iterator<Iterator1>& lhs, |
(直到 C++17) | |
template< class Iterator1, class Iterator2 > constexpr bool operator>=( const std::move_iterator<Iterator1>& lhs, |
(从 C++17 开始) | |
template< class Iterator1, std::three_way_comparable_with<Iterator1> Iterator2 > constexpr std::compare_three_way_result_t<Iterator1, Iterator2> |
(7) | (从 C++20 开始) |
比较底层迭代器。
(1-6) 只有当它们的底层比较表达式(见下文)格式正确且可转换为 bool 时,才能参与重载解析。
|
(从 C++20 开始) |
内容 |
[编辑] 参数
lhs, rhs | - | 要比较的迭代器适配器 |
[编辑] 返回值
[编辑] 示例
#include <compare> #include <iostream> #include <iterator> int main() { int a[]{9, 8, 7, 6}; // │ └───── x, y // └──────── z std::move_iterator<int*> x{std::end(a) - 1}, y{std::end(a) - 1}, z{std::end(a) - 2}; std::cout << std::boolalpha << "*x == " << *x << '\n' // 6 << "*y == " << *y << '\n' // 6 << "*z == " << *z << '\n' // 7 << "x == y ? " << (x == y) << '\n' // true << "x != y ? " << (x != y) << '\n' // false << "x < y ? " << (x < y) << '\n' // false << "x <= y ? " << (x <= y) << '\n' // true << "x == z ? " << (x == z) << '\n' // false << "x != z ? " << (x != z) << '\n' // true << "x < z ? " << (x < z) << '\n' // false << "x <= z ? " << (x <= z) << '\n' // false << "x <=> y == 0 ? " << (x <=> y == 0) << '\n' // true << "x <=> y < 0 ? " << (x <=> y < 0) << '\n' // false << "x <=> y > 0 ? " << (x <=> y > 0) << '\n' // false << "x <=> z == 0 ? " << (x <=> z == 0) << '\n' // false << "x <=> z < 0 ? " << (x <=> z < 0) << '\n' // true << "x <=> z > 0 ? " << (x <=> z > 0) << '\n' // false ; }
输出
*x == 6 *y == 6 *z == 7 x == y ? true x != y ? false x < y ? false x <= y ? true x == z ? false x != z ? true x < z ? false x <= z ? false x <=> y == 0 ? true x <=> y < 0 ? false x <=> y > 0 ? false x <=> z == 0 ? false x <=> z < 0 ? false x <=> z > 0 ? true
[编辑] 参见
比较底层迭代器和底层哨兵 (函数模板) |