Section hub

std::ranges::views::stride, std::ranges::stride_view

  1. stride_view is a range adaptor that takes a view and a number n and produces a view, that consists of elements of the original view by advancing over n elements at a time. This means that each mth element of the produced view is (n * i)th element of the original view, for some non-negative index i. The elements of the original view, whose “index” is not a multiple of n, are not present in the produced view.

# Declarations

template< ranges::input_range V >
requires ranges::view<V>
class stride_view
: public ranges::view_interface<stride_view<V>>

(since C++23)

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

(since C++23)

Call signature
template< ranges::viewable_range R >
constexpr ranges::view auto stride( R&& r, ranges::range_difference_t<R> n );

(since C++23)

template< class DifferenceType >
constexpr /*range adaptor closure*/ stride( DifferenceType&& n );

(since C++23)

Helper templates

# Notes

Feature-test macro Value Std Feature __cpp_lib_ranges_stride 202207L (C++23) std::ranges::stride_view

# Example

#include <algorithm>
#include <iostream>
#include <ranges>
#include <string_view>
using namespace std::literals;
 
void print(std::ranges::viewable_range auto&& v, std::string_view separator = " ")
{
    for (auto const& x : v)
        std::cout << x << separator;
    std::cout << '\n';
}
 
int main()
{
    print(std::views::iota(1, 13) | std::views::stride(3));
    print(std::views::iota(1, 13) | std::views::stride(3) | std::views::reverse);
    print(std::views::iota(1, 13) | std::views::reverse | std::views::stride(3));
 
    print("0x0!133713337*x//42/A$@"sv | std::views::stride(0B11) |
          std::views::transform([](char O) -> char { return 0100 | O; }),
          "");
}

# 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