std::ranges...:operator[](3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… 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