最終更新日時(UTC):
が更新

履歴 編集

function
<ranges>

std::ranges::iota_view::コンストラクタ(C++20)

// (1)
iota_view() = default;

// (2)
constexpr explicit iota_view(W value);

// (3)
constexpr iota_view(type_identity_t<W> value, type_identity_t<Bound> bound);

// (4)
constexpr iota_view(iterator first, sentinel last);

概要

  • (1) : [W(), Bound()) を範囲とするiota_viewを構築する
  • (2) : [value, Bound()) を範囲とするiota_viewを構築する
  • (3) : [value, bound) を範囲とするiota_viewを構築する
  • (4) : イテレータ [first, last) が指す値を範囲とするiota_viewを構築する((3)に委譲)

Boundunreachable_sentinel_tのとき、無限長のiota_viewとなる。

事前条件

ebから到達できるとは、bをn回インクリメントしたとき、e == bが真となるようなnが存在することをいう。

効果

iota_viewが内部で保持する先頭と終端の値を引数で初期化する。

#include <ranges>

int main()
{
  // 無限長
  constexpr std::ranges::iota_view iota1{0};
  static_assert(not std::ranges::sized_range<decltype(iota1)>);
  static_assert(iota1.front() == 0);

  // 1引数だが、Boundがintなので、範囲は [-5, int()) すなわち [-5, 0) となり有限長
  constexpr std::ranges::iota_view<int, int> iota2{-5};
  static_assert(std::ranges::size(iota2) == 5);

  // iota_viewの部分範囲
  constexpr std::ranges::iota_view iota3{0, 10};
  constexpr decltype(iota3) sub{iota3.begin() + 3, iota3.end()};
  static_assert(sub.front() == 3);
}

出力

バージョン

言語

  • C++20

処理系

参照