名前空間
変種
操作

operator==, <>=

From cppreference.com
 
 
イテレータライブラリ
イテレータのコンセプト
イテレータのプリミティブ
アルゴリズムのコンセプトとユーティリティ
間接呼び出し可能コンセプト
共通アルゴリズム要件
(C++20)
(C++20)
(C++20)
ユーティリティ
(C++20)
イテレータアダプタ
Rangeアクセス
(C++11)(C++14)
(C++14)(C++14)  
(C++11)(C++14)
(C++14)(C++14)  
(C++17)(C++20)
(C++17)
(C++17)
 
 
template< std::common_with<I> I2 >

    friend constexpr bool operator==(

        const counted_iterator& x, const counted_iterator<I2>& y );
(1) (C++20以降)
template< std::common_with<I> I2 >

    friend constexpr strong_ordering operator<=>(

        const counted_iterator& x, const counted_iterator<I2>& y );
(2) (C++20以降)

基になる長さを比較します (つまり、終点までの距離)。

1) 基になる長さが等しいかどうかをチェックします。
2) 基になる長さを operator <=> で比較します。

もし xy が同じシーケンスの要素を指していない場合、その動作は未定義です。つまり、ある n が存在し、std::next(x.base(), x.count() + n) および std::next(y.base(), y.count() + n) が同じ要素を参照する必要があります。

<, <=, >, >=, != 演算子は、それぞれ operator<=>operator== から合成されます。

この関数テンプレートは、通常の非修飾または修飾ルックアップからは見えず、std::counted_iterator<I> が引数の関連クラスである場合にのみ、引数依存の名前探索によって見つけることができます。

目次

[edit] パラメータ

x, y - イテレータアダプタ

[edit] 戻り値

1) x.count() == y.count()
2) y.count() <=> x.count()

[edit] 注記

長さはカウントアップではなくカウントダウンするため、基になる比較式での operator<=> の引数の順序は逆になります。つまり、ylhsxrhs になります。

[edit]

#include <initializer_list>
#include <iterator>
 
int main()
{
    static constexpr auto v = {1, 2, 3, 4, 5, 6};
    constexpr std::counted_iterator<std::initializer_list<int>::iterator>
        it1{v.begin(), 5},
        it2{v.begin(), 5},
        it3{v.begin() + 1, 4},
        it4{v.begin(), 0};
    static_assert(it1 == it2);
    static_assert(it2 != it3);
    static_assert(it2 <  it3);
    static_assert(it1 <= it2);
    static_assert(it3 != std::default_sentinel);
    static_assert(it4 == std::default_sentinel);
 
//  it2 == std::counted_iterator{v.begin(), 4}; // UB: operands do not refer to
                                                // elements of the same sequence
}

[edit] 関連項目

終点までの距離が ​0​ に等しいかどうかをチェックします。
(関数テンプレート) [edit]
(C++20)
イテレータを進める
(関数テンプレート) [編集]
(C++20)
2つのイテレータアダプタ間の距離を計算する
(関数テンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)