std::ranges...view::begin(3)
π std::ranges::slide_view::begin
ok so this is a page straight out of the C++ Standard Library manual (yes, that one β cppreference energy, group-chat edition) and the star of the show is std::ranges::slide_view::begin π
Fair warning bestie: the header up top is literally the title again (std::ranges::slide_view::begin, if you were wondering), so likeβ¦ yeah. It's giving "name so nice they said it twice." πΈ
β¨ NAME β¨
std::ranges::slide_view::begin β and yeah, that's it, that's the name. std::ranges::slide_view::begin. The whole thing. No cap. π
π¦ Synopsis π¦
okay so there are two overloads and they both showed up in C++23, and both are constexpr. Here's the exact shape, copy-paste energy:
constexpr auto begin()
requires (!(__simple_view<V> && __slide_caches_nothing<const V>));
(1) (since C++23)
constexpr auto begin() const
requires __slide_caches_nothing<const V>;
(2) (since C++23)
What this function does: it returns an iterator to the first element of the slide_view. Simple queen behaviour. π
Now for the receipts β here's what each overload is equivalent to:
1) If V models __slide_caches_first, it's equivalent to:
return iterator<false>(
ranges::begin(base_),
ranges::next(ranges::begin(base_), n_ - 1,
ranges::end(base_)),
n_
);
Otherwise, it's equivalent to: return iterator<false>(ranges::begin(base_), n_);
And ooh, this part matters: if V models __slide_caches_first, this function caches the result within the slide_view::cached_begin_ for use on subsequent calls. Why, you ask? Because that's necessary to provide the amortized constant-time complexity that the range requires. So the cache is not optional, it's the whole point. β
2) Equivalent to: return iterator<true>(ranges::begin(base_), n_);
π Parameters π
- (none) β yeah, nothing. Empty. Nada. She takes no arguments, she's booked and busy. π
π₯ Return value π₯
An iterator to the first element of slide_view, which points to the n_-sized subrange of the possibly const-qualified underlying view type β that's V for overload (1), or const V for overload (2). β¨
Like, which one you get depends on which overload you called. Keep that straight and you're slaying. π
π Example π
// Run this code β go on, run it, I'll wait π
#include <iostream>
#include <ranges>
#include <string_view>
using namespace std::literals;
int main()
{
static constexpr auto source = {"βx"sv, "βy"sv, "Ξ΅"sv, "Ξ΄"sv};
auto view{std::ranges::slide_view(source, 2)};
const auto subrange{*(view.begin())};
for (std::string_view const s : subrange)
std::cout << s << ' ';
std::cout << '\n';
}
π Output π
βx βy
bestie look at those little logic symbols go π absolutely iconic.
π See also π
endβ returns an iterator or a sentinel to the end (C++23) (public member function)operator==β compares a sentinel with an iterator returned fromslide_view::begin(C++23) (function)
ok that's the whole page!! π«Ά big shoutout to http://cppreference.com for hosting it, version 2024.06.10, and to the man page itself living its best life under the very cursed-but-iconic name std::ranges...view::begin(3) (yes, with the three dots, don't @ me π). mwah, go read more man pages, ily π§π
π¦ 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