std::ranges...e_view::end(3)
π std::ranges::slide_view::end(3) β the C++ Standard Library one
okay so bestie, buckle up, because this is the std::ranges::slide_view::end page π β straight out of the C++ Standard Library, and it's honestly kind of a serve once you get past the underscores. it's giving "end iterator, but make it fashion" β¨
πΈ SYNOPSIS
no arguments, just vibes and constexpr:
constexpr auto end()
requires (!(__simple_view<V> && __slide_caches_nothing<const V>));
(1) (since C++23)
constexpr auto end() const
(2) (since C++23)
requires __slide_caches_nothing<const V>;
so there are literally two overloads, both constexpr, both since C++23 π and both of them hand you a sentinel or an iterator that represents the end of the slide_view. that's the whole job. icon behaviour honestly.
β¨ DESCRIPTION
π«Ά Overload (1)
let base_ and n_ be the underlying data members (yes bestie, they're private, don't touch). this overload is equivalent to a little four-way vibe check:
- if
Vmodels__slide_caches_nothing, returniterator<false>(ranges::begin(base_) + ranges::range_difference_t<V>(size()), n_);. - otherwise, if
Vmodels__slide_caches_last, returniterator<false>(ranges::prev(ranges::end(base_), n_ - 1, ranges::begin(base_)), n_);. - otherwise, if
Vmodelscommon_range, returniterator<false>(ranges::end(base_), ranges::end(base_), n_);. - otherwise, return
sentinel(ranges::end(base_));.
and here's the tea β β if V models __slide_caches_last, this function caches the result inside the slide_view::cached_end_ for use on subsequent calls. why? because that's literally necessary to provide the amortized constant-time complexity that the range is required to have. no cap, the caching is load-bearing π
π¦ Overload (2)
the const one, and it's short and sweet. equivalent to:
begin() + ranges::range_difference_t<const V>(size())
periodt. that's it. that's the whole overload π
π PARAMETERS
- (none) β not a single parameter, bestie. zero. nada. she takes nothing π
π RETURN VALUE
a sentinel or an iterator that represents the end of the slide_view β β same deal as above, just restated because the standard library loves a callback.
π₯ EXAMPLE
run this code, it's cute:
// Run this code
#include <iostream>
#include <ranges>
int main()
{
static constexpr auto source = {'A', 'B', 'C', 'D'};
for (const auto subrange: source | std::views::slide(3))
{
std::cout << "[ ";
for (auto it = subrange.begin(); it != subrange.end(); ++it)
std::cout << *it << ' ';
std::cout << "]\n";
}
}
Output:
[ A B C ]
[ B C D ]
look at those sliding windows go π sliding so gracefully. main character energy fr fr πΈ
π SEE ALSO
beginβ returns an iterator to the beginning (C++23) (public member function)ranges::beginβ returns an iterator to the beginning of a range (C++20) (customization point object)ranges::endβ returns a sentinel indicating the end of a range (C++20) (customization point object)
π tiny reminder bestie: those double-underscore names like__slide_caches_nothing,__slide_caches_last,__simple_viewand__slide_caches_lastare implementation-reserved β admire them from a distance, don't go writing them in your own code, iykyk π«Ά
and that's the page!! shoutout to cppreference.com, dated 2024.06.10 β the source and version that made this whole little writeup possible π β¨ go slide responsibly, 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