std::ranges..._view::begin(3)
β¨ std::ranges::adjacent_view::begin β¨
okay so this is the begin member of std::ranges::adjacent_view, from the C++ Standard Libary (yes bestie, the header really spells it like that, we don't fix it, we respect it π
). Manual name: std::ranges..._view::begin, section 3. Let's get into it π«Ά
πΈ Synopsis πΈ
constexpr auto begin() requires (!__SimpleView<V>); (1)
(since C++23)
constexpr auto begin() const requires ranges::range<const V>; (2)
(since C++23)
So like, this gives you an iterator pointing at the first element of the adjacent_view. Main character energy honestly π
Let base_ be the underlying view, okay? Remember that name, it comes back.
- Overload (1) is equivalent to
return /*iterator*/<false>(ranges::begin(base_), ranges::end(base_));. - Overload (2) is equivalent to
return /*iterator*/<true>(ranges::begin(base_), ranges::end(base_));.
(those divergence comments are literally part of the deal, don't @ me, they're in the standard π)
π Parameters π
none. zero. nothing. no arguments, no stress, no cap. β¨
π¦ Return value π¦
An iterator to the first element. that's it, that's the whole vibe π
π₯ Example π₯
Run this code π
#include <ranges>
#include <tuple>
#include <type_traits>
int main()
{
constexpr static auto v = {'A', 'B', 'C', 'D', 'E'};
constexpr auto view = std::views::adjacent<3>(v);
constexpr auto tuple = *view.begin();
static_assert
(
std::is_same_v
<
decltype(tuple),
const std::tuple<char const&, char const&, char const&>
>
);
static_assert
(
std::get<0>(tuple) == 'A' &&
std::get<1>(tuple) == 'B' &&
std::get<2>(tuple) == 'C'
);
}
like... it grabs the first tuple of three adjacent elements and it's literally 'A', 'B', 'C'. the static_asserts ate and left no crumbs π
π See also π
endβ returns an iterator or a sentinel to the end (C++23) (public member function)ranges::beginβ returns an iterator to the beginning of a range (C++20) (customization point object)
aaaand that's the page bestie π§ go forth and iterate. source: http://cppreference.com, dated 2024.06.10 β this one goes out to the C++ Standard Libary manpage crew, 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