std::ranges...:operator[](3)
π std::ranges...:operator[](3) π
okay so this page is from the C++ Standard Libary manual β yes, that's literally the spelling in the header, iykyk π β and it's all about std::ranges::stride_view::iterator::operator[]. C++23 energy only, bestie β¨
π NAME π
std::ranges::stride_view::iterator::operator[]β the first line of the NAME block, periodt.std::ranges::stride_view::iterator::operator[]β the second line, same name, iconic repetition π
β¨ Synopsis β¨
constexpr decltype(auto) operator[]( difference_type n ) const
(since C++23)
requires ranges::random_access_range<Base>
This one is constexpr, returns decltype(auto), takes a difference_type n, and is const. The since C++23 is giving new-standard energy, and the requires clause is ranges::random_access_range<Base> β random access range only, no cap π₯
Returns an element at specified relative location. It's equivalent to return *(*this + n); β literally that, bestie.
πΈ Parameters πΈ
nβ position relative to current location.
π Return value π
The element at displacement n relative to the current location. That's the whole vibe π
π¦ Example π¦
// Run this code
#include <ranges>
int main()
{
constexpr static auto v = {'a', 'b', 'c', 'd', 'e'};
constexpr auto view{v | std::views::stride(2)};
constexpr auto iter{view.begin() + 1};
static_assert(*iter == 'c');
static_assert(iter[0] == 'c');
static_assert(iter[1] == 'e');
}
The static_asserts are literally checking that *iter == 'c', iter[0] == 'c', and iter[1] == 'e' β cute little vibe checks, slay π
β See also β
operator*β accesses an element (C++23) (public member function).
source: http://cppreference.com Β· date: 2024.06.10 β that's the footer, bestie, so you're fully caught up. go index something cute π«Άπ
π¦ 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