Skip to content

Latest commit

 

History

History
68 lines (54 loc) · 2.45 KB

sentinel.md

File metadata and controls

68 lines (54 loc) · 2.45 KB

sentinel

  • ranges[meta header]
  • std::ranges[meta namespace]
  • iota_view[meta class]
  • class template[meta id-type]
  • cpp20[meta cpp]

概要

iota_viewが有限長かつcommon_rangeではない場合の番兵型。

iota_viewの終端要素型の値を1つ記憶していて、比較演算は内部の値同士の比較となる。

このクラスの名前は規定されておらず、振る舞いのみが規定されている。

このクラスの型を取得したい場合、sentinel_tを使用できる。

なお、iota_viewの番兵型は、無限長のときはunreachable_sentinel_t、有限長でcommon_rangeのときはiteratorである。

実装例

namespace std::ranges {
  template<weakly_incrementable W, semiregular Bound>
    requires weakly-equality-comparable-with<W, Bound>
  struct iota_view<W, Bound>::sentinel {
  private:
    Bound bound_ = Bound();
  public:
    sentinel() = default;
    constexpr explicit sentinel(Bound bound): bound_{bound} {
    }

    friend constexpr bool operator==(const iterator& x, const sentinel& y) {
      return x.value_ == y.bound_;
    }

    friend constexpr iter_difference_t<W> operator-(const iterator& x, const sentinel& y) requires sized_sentinel_for<Bound, W> {
      return x.value_ - y.bound_;
    }

    friend constexpr iter_difference_t<W> operator-(const sentinel& x, const iterator& y) requires sized_sentinel_for<Bound, W> {
      return -(y - x);
    }
  };
}
  • iterator[link iterator.md]
  • iota_view[link ../iota_view.md]
  • weakly_incrementable[link /reference/iterator/weakly_incrementable.md]
  • sized_sentinel_for[link /reference/iterator/sized_sentinel_for.md]
  • iter_difference_t[link /reference/iterator/iter_difference_t.md]
  • semiregular[link /reference/concepts/semiregular.md]
  • weakly-equality-comparable-with[link /reference/concepts/equality_comparable.md]

バージョン

言語

  • C++20

処理系

  • Clang: 13.0.0 [mark verified]
  • GCC: 10.1.0 [mark verified]
  • ICC: ?
  • Visual C++: 2019 Update 10 [mark verified]

参照