Section hub

std::ranges::views::iota, std::ranges::iota_view

  1. A range factory that generates a sequence of elements by repeatedly incrementing an initial value. Can be either bounded or unbounded (infinite).

# Declarations

template< std::weakly_incrementable W,
std::semiregular Bound = std::unreachable_sentinel_t >
requires /*weakly-equality-comparable-with*/<W, Bound> && std::copyable<W>
class iota_view
: public ranges::view_interface<iota_view<W, Bound>>

(since C++20)

namespace views {
inline constexpr /* unspecified */ iota = /* unspecified */;
}

(since C++20)

Call signature
template< class W >
requires /* see below */
constexpr /* see below */ iota( W&& value );

(since C++20)

template< class W, class Bound >
requires /* see below */
constexpr /* see below */ iota( W&& value, Bound&& bound );

(since C++20)

# Example

#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';
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 4096C++20views::iota could copy an iota_view as-isforbidden
P2325R3C++20iota_view required that W is semiregularas view required default_initializableonly requires that W is copyable

# See also

This hub groups the ranges library by user task rather than by raw reference tree shape. View types and adaptor objects are presented as the same conceptual item.

Core adapters

Start here for the adapters most people reach for first when building pipelines.

Utility views

These adapt shape, ownership, or projection rather than representing the “headline” pipeline steps.

New in C++23 / C++26

Newer adapters, kept as a compact scan list with only standard badges.

All entities by category

A lighter-weight index of the full ranges surface, grouped by conceptual task instead of raw page-tree names.

74 entities