// (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)に委譲)
Bound
がunreachable_sentinel_t
のとき、無限長のiota_view
となる。
事前条件
e
がb
から到達できるとは、b
をn回インクリメントしたとき、e == b
が真となるようなnが存在することをいう。
- (2):
Bound
はunreachable_sentinel_t
である。または、Bound()
はvalue
から到達できる - (3):
Bound
はunreachable_sentinel_t
である。または、bound
はvalue
から到達できる。totally_ordered_with<W, Bound>
ならば、bool(value <= bound)
がtrue
である
効果
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);
}
19
#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
処理系
- Clang: 13.0.0 ✅
- GCC: 10.1.0 ✅
- ICC: ?
- Visual C++: 2019 Update 10 ✅