Defined in header
template<std::weakly_incrementableW,std::semiregularBound=std::unreachable_sentinel_t>requires/*weakly-equality-comparable-with*/<W,Bound>&&std::copyable<W>classiota_view:publicranges::view_interface<iota_view<W,Bound>> (1) (since C++20)namespaceviews{inlineconstexpr/* unspecified */iota=/* unspecified */;} (2) (since C++20)namespaceviews{inlineconstexpr/* unspecified */indices=/* unspecified */;} (3)(since C++26)Call signature
template<classW>requires/* see below */constexpr/* see below */iota(W&&value);(since C++20)template<classW,classBound>requires/* see below */constexpr/* see below */iota(W&&value,Bound&&bound);(since C++20)template<classT>requires/*is-integer-like*/<T>constexpr/* see below */indices(Tbound);(since C++26)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
to iota_view<std::decay_t<decltype((e))>>(e) and iota_view(e,f) respectively for any suitable subexpressions e and f.
3) Let T be std::remove_cvref_t<decltype((e))>. Then views::indices(e) is
to views::iota(T(0),e) for any suitable subexpression e if T is an
.
Customization point objects
The name views::iota denotes a customization point object, which is a const
of a
class type. See
for details.
Data members
Member Description Wvalue_the beginning value
(exposition-only member object*)Boundbound_the sentinel value, may be unreachable
(exposition-only member object*)Member functions
creates an iota_view
(public member function)
obtains the beginning iterator of an iota_view
(public member function)
obtains the sentinel denoting the end of an iota_view
(public member function)
tests whether the iota_view is empty (i.e. the iterator and the sentinel compare equal)
(public member function)
(optional)
obtains the size of an iota_view (only provided if it is bounded)
(public member function) Inherited from
(C++23)
returns a constant iterator to the beginning of the range
(public member function of std::ranges::view_interface<D>)
(C++23)
returns a sentinel for the constant iterator of the range
(public member function of std::ranges::view_interface<D>)
returns whether the derived view is not empty, provided only if
is applicable to it
(public member function of std::ranges::view_interface<D>)
returns the first element in the derived view, provided if it satisfies
(public member function of std::ranges::view_interface<D>)
returns the last element in the derived view, provided only if it satisfies
and
(public member function of std::ranges::view_interface<D>)
returns the nth element in the derived view, provided only if it satisfies
(public member function of std::ranges::view_interface<D>)
Nested classes
the iterator type
(exposition-only member class*)the sentinel type used when the iota_view is bounded and Bound and W are not the same type
(exposition-only member class*)Helper templates
template<std::weakly_incrementableW,std::semiregularBound>constexprboolranges::enable_borrowed_range<ranges::iota_view<W,Bound>>=true;(since C++20)This specialization of ranges::enable_borrowed_range makes iota_view satisfy
.
Possible implementation
See also the implementation in
.
namespaceviews{inlineconstexprautoindices=[]</*is-integer-like*/I>(In){returnviews::iota(I{},n);};}Notes
macro ValueStdFeature
(C++26)ranges::views::indicesExample
Run this code
#include<print>#include<ranges>structBound{intbound;booloperator==(intx)const{returnx==bound;}};intmain(){std::print("{}\n",std::ranges::iota_view{1,10});std::print("{}\n",std::views::iota(1,10));std::print("{}\n",std::views::iota(1,Bound{10}));std::print("{}\n",std::views::iota(1)|std::views::take(9));constexprintv[]{9,8,7,6,5,4,3,2,1};// auto broken_indices = views::iota(0, std::ranges::size(v));// does not compile due to types (int VS size_t) mismatchautogood_indices=std::views::indices(std::ranges::size(v));std::print("{}\n",good_indices);}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] [0, 1, 2, 3, 4, 5, 6, 7, 8] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
C++20 views::iota could copy an iota_view as-is forbidden
C++20 iota_view required that W is
as
required
only requires that W is
References
C++26 standard (ISO/IEC 14882:2026):
25.6.4 Iota view [range.iota]
C++23 standard (ISO/IEC 14882:2024):
26.6.4 Iota view [range.iota]
C++20 standard (ISO/IEC 14882:2020):
24.6.4 Iota view [range.iota]
See also