std::ranges...:operator[](3)
π std::ranges...:operator[](3) π
okay bestie, this page is from the C++ Standard Libary manual (yes, that's how the header spells it β we're keeping the typo, no cap π«Ά). It's the std::ranges::adjacent_view::iterator::operator[] page, and it's giving C++23 iterator energy.
πΈ NAME πΈ
std::ranges::adjacent_view::iterator::operator[] -
std::ranges::adjacent_view::iterator::operator[]
literally that's the name: std::ranges::adjacent_view::iterator::operator[] twice with a hyphen in the middle. slay.
β¨ Synopsis β¨
okay so this operator[] has been a thing since C++23, and it only exists when this constraint is satisfied:
constexpr auto operator[]( difference_type n ) const (since C++23)
requires ranges::random_access_range<Base>;
It returns an element at specified relative location. Let current_ be an underlying array of iterators. Equivalent to:
return __tuple_transform([&](auto& i) -> decltype(auto) { return i[n];
}, current_);
π Parameters π
nβ position relative to current location. that's it, that's the whole parameter π
π Return value π
The element at displacement n relative to the current location. periodt. β¨
π¦ Example π¦
run this code, bestie:
// Run this code
#include <ranges>
#include <tuple>
int main()
{
constexpr static auto v = {0, 1, 2, 3, 4, 5};
// ββββ¬βββ
// βββββββββββββββββββ
constexpr auto view = v | std::views::adjacent<3>; // β
// βββββββββββββββββββββ¬βββββββββββββββ
// β ββββ΄βββ
static_assert(view[2] == std::tuple{2, 3, 4});
}
the static_assert says view[2] == std::tuple{2, 3, 4} and it passes, no cap π₯
π sourced fromhttp://cppreference.com, version dated2024.06.10, pagestd::ranges...:operator[](3)β bye bestie, stay random-access πβ¨
π¦ 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