std::ranges::views::iota, std::ranges::iota_view
Defined in header <ranges>
|
||
template<std::weakly_incrementable W, std::semiregular Bound = std::unreachable_sentinel_t> |
(1) | (since C++20) |
namespace views { inline constexpr /*unspecified*/ iota = /*unspecified*/; |
(2) | (since C++20) |
E
and F
Contents |
Expression-equivalent
Expression e is expression-equivalent to expression f, if
- e and f have the same effects, and
- either both are constant subexpressions or else neither is a constant subexpression, and
- either both are potentially-throwing or else neither is potentially-throwing (i.e. noexcept(e) == noexcept(f)).
Helper templates
template<std::weakly_incrementable W, std::semiregular Bound> inline constexpr bool enable_borrowed_range<ranges::iota_view<W, Bound>> = true; |
||
This specialization of std::ranges::enable_borrowed_range makes iota_view
satisfy borrowed_range
.
Data members
std::ranges::iota_view::base_
W value_ = W(); /* exposition-only */ |
||
the current value
std::ranges::iota_view::bound_
Bound bound_ = Bound(); /* exposition-only */ |
||
the bound (defaults to std::unreachable_sentinel_t)
Member functions
std::ranges::iota_view::iota_view
iota_view() = default; |
(1) | |
constexpr explicit iota_view(W value); |
(2) | |
constexpr iota_view(std::type_identity_t<W> value, std::type_identity_t<Bound> bound); |
(3) | |
value_
and bound_
.value_
with value and value-initializes bound_
. This constructor is used to create unbounded iota_view
s, e.g. iota(0) yields numbers 0,1,2..., infinitely.value_
with value and bound_
with bound. The behavior is undefined if std::totally_ordered_with<W, Bound> is modeled and bool(value <= bound) is false. This constructor is used to create bounded iota views, e.g. iota(10, 20) yields numbers from 10 to 19.For (2) and (3), the behavior is undefined if the iota_view
is bounded (i.e. Bound
is not std::unreachable_sentinel_t) and bound_
is initialized to a value unreachable from value.
Parameters
value | - | the starting value |
bound | - | the bound |
std::ranges::iota_view::begin
constexpr /*iterator*/ begin() const; |
||
Returns an iterator initialized with value_.
std::ranges::iota_view::end
constexpr auto end() const; |
(1) | |
constexpr /*iterator*/ end() const requires std::same_as<W, Bound>; |
(2) | |
std::ranges::iota_view::size
constexpr auto size() const requires (std::same_as<W, Bound> && __Advanceable<W>) || |
||
Returns the size of the view if the view is bounded.
Deduction guides
template<class W, class Bound> requires (!__IsIntegerLike<W> || !__IsIntegerLike<Bound> || |
||
Note that the guide protects itself against signed/unsigned mismatch bugs, like views::iota(0, v.size()), where 0
is a (signed) int
and v.size()
is an (unsigned) std::size_t
.
Nested classes
the iterator type (public member class) | |
the sentinel type used when the iota_view is bounded and Bound and W are not the same type (public member class) |
Example
#include <ranges> #include <iostream> int main() { for (int i : std::ranges::iota_view{1, 10}) std::cout << i << ' '; std::cout << '\n'; for (int i : std::views::iota(1, 10)) std::cout << i << ' '; std::cout << '\n'; for (int i : std::views::iota(1) | std::views::take(9)) std::cout << i << ' '; std::cout << '\n'; }
Output:
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9