std::ranges::views::iota, std::ranges::iota_view
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Ranges library
(exposition-only member object*)
(exposition-only member object*)
obtains the size of an
(public member function)
returns a constant iterator to the beginning of the range
(public member function of
returns a sentinel for the constant iterator of the range
(public member function of
fills a range with successive increments of the starting value
(algorithm function object)[edit]
a
(class template) (customization point object)[edit]
(C++23)(C++23)
iota_viewviews::iota
(C++23)(C++23)
(C++23)(C++23)
(C++26)(C++26)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)
(C++23)(C++23)
(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)
std::ranges::iota_view
Defined in header
<ranges>
template< std::weakly_incrementable W,
(1)
(since C++20)
std::semiregular Bound = std::unreachable_sentinel_t >
requires /*weakly-equality-comparable-with*/<W, Bound> && std::copyable <W>
class iota_view
namespace views {
(2)
(since C++20)
inline constexpr /* unspecified */ iota = /* unspecified */;
Call signature
template< class W >
(since C++20)
requires /* see below */
template< class W, class Bound >
(since C++20)
requires /* see below */
1) A range factory that generates a sequence of elements by repeatedly incrementing an initial value. Can be either bounded or unbounded (infinite).
2) views::iota(e) and views::iota(e, f) are expression-equivalent to iota_view<std::decay_t <decltype((e))>>(e) and iota_view(e, f) respectively for any suitable subexpressions e and f.
Contents
Customization point objects
The name views::iota
denotes a customization point object, which is a const function object of a literal semiregular
class type. See CustomizationPointObject for details.
[edit] Data members
Member
Definition
W
value_
the beginning value(exposition-only member object*)
Bound
bound_
the sentinel value, may be unreachable(exposition-only member object*)
[edit] Member functions
tests whether the
(public member function)
iota_view
is empty (i.e. the iterator and the sentinel compare equal) (public member function)
(optional)
iota_view
(only provided if it is bounded) (public member function)
Inherited from std::ranges::view_interface
(C++23)
(public member function of
std::ranges::view_interface<D>
) [edit]
(C++23)
(public member function of
std::ranges::view_interface<D>
) [edit]
returns whether the derived view is not empty, provided only if ranges::empty is applicable to it
(public member function of
(public member function of
std::ranges::view_interface<D>
) [edit]
returns the first element in the derived view, provided if it satisfies
(public member function of
forward_range
(public member function of
std::ranges::view_interface<D>
) [edit]
returns the last element in the derived view, provided only if it satisfies
(public member function of
bidirectional_range
and common_range
(public member function of
std::ranges::view_interface<D>
) [edit]
returns the
(public member function of
n
th element in the derived view, provided only if it satisfies random_access_range
(public member function of
std::ranges::view_interface<D>
) [edit]
[edit] Deduction guides
[edit] Nested classes
the sentinel type used when the
(exposition-only member class*)
iota_view
is bounded and Bound
and W
are not the same type(exposition-only member class*)
[edit] Helper templates
template< std::weakly_incrementable W, std::semiregular Bound >
constexpr bool ranges::enable_borrowed_range <ranges::iota_view<W, Bound>> = true;
(since C++20)
constexpr bool ranges::enable_borrowed_range <ranges::iota_view<W, Bound>> = true;
This specialization of ranges::enable_borrowed_range makes iota_view
satisfy borrowed_range
.
[edit] Example
Run this code
#include <algorithm> #include <iostream> #include <ranges> struct Bound { int bound; bool operator==(int x) const { return x == bound; } }; 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, Bound{10})) std::cout << i << ' '; std::cout << '\n'; for (int i : std::views::iota(1) | std::views::take (9)) std::cout << i << ' '; std::cout << '\n'; std::ranges::for_each (std::views::iota(1, 10), [](int i){ 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 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 4096 | C++20 | views::iota could copy an iota_view as-is
|
forbidden |
P2325R3 | C++20 | iota_view required that W is semiregular as view required default_initializable
|
only requires that W is copyable
|
[edit] See also
(C++23)
(algorithm function object)[edit]
(C++23)
view
consisting of a generated sequence by repeatedly producing the same value(class template) (customization point object)[edit]