std::ranges...:stride_view(3)
π std::ranges::stride_view::stride_view
okay so bestie, this is the std::ranges::stride_view::stride_view page from the C++ Standard Library manual (we're in cppreference.com territory, the girlies who actually read it know π). It's literally just the constructor. The whole page. One constructor. And honestly? She ate. Let's get into it π
β¨ NAME β¨
std::ranges::stride_view::stride_view β yes the name is the name twice, that's not a typo, that's just how constructors roll π
πΈ Synopsis πΈ
constexpr explicit stride_view( V base, ranges::range_difference_t<V>
stride );
(since C++23) π¦
So what does she do? She constructs a stride_view and initializes the underlying data members, no cap:
- move construct the underlying view
base_withstd::move(base), - construct the
stride_withstride.
β οΈ Heads up bestie: if stride < 1 the behavior is undefined. Like, not "it'll be fiiiine" undefined β actually undefined. Do not test her. π
π§ Parameters π§
baseβ the source view πstrideβ the stride value β¨
π₯ Example π₯
// Run this code
#include <algorithm>
#include <iostream>
#include <iterator>
#include <ranges>
#include <string_view>
void print(std::string_view rem, auto v, std::string_view term = "\n")
{
std::cout << rem << ": ";
std::ranges::copy(v, std::ostream_iterator<int>(std::cout, " "));
std::cout << term;
};
int main()
{
auto source = std::views::iota(1, 10);
print("source", source);
for (int stride_value : std::views::iota(1, 6))
{
auto strided_view = std::views::stride(source, stride_value);
print("stride", std::views::single(stride_value), "-> ");
print("result", strided_view);
}
}
β Output β
source: 1 2 3 4 5 6 7 8 9
stride: 1 -> result: 1 2 3 4 5 6 7 8 9
stride: 2 -> result: 1 3 5 7 9
stride: 3 -> result: 1 4 7
stride: 4 -> result: 1 5 9
stride: 5 -> result: 1 6
like look at that output π every stride just picks her little faves out of the source and dips. iconic behavior honestly. π
and that's the whole page, bestie β short and sweet, just like she is π«Ά this one came from cppreference.com, dated 2024.06.10, and that's the vibe check for std::ranges::stride_view(3). mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms