std::ranges...r::operator*(3)

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

✨ NAME ✨

okay so bestie, this is the std::ranges...r::operator*(3) page from the C++ Standard Libary manual (yes, the header literally spells it β€œLibary” β€” we love a typo era πŸ’…), and it’s all about dereferencing an iterator from elements_view. Let’s get into it 🫢

std::ranges::elements_view::iterator::operator* β€” std::ranges::elements_view::iterator::operator*


🌸 SYNOPSIS 🌸

constexpr decltype(auto) operator*() const;  (since C++20)

This returns the element into V that the underlying iterator points to. No cap, that’s the whole vibe ✨

Effectively returns /*get-element*/(this->base()), where for an expression e, /*get-element*/(e) is:

  • *std::get<N>(*e), if ranges::range_reference_t<Base> is a reference type. Otherwise,
  • static_cast<E>(std::get<N>(*e)), where E is std::remove_cv_t<std::tuple_element_t<N, ranges::range_reference_t<Base>>>.

πŸŽ€ PARAMETERS πŸŽ€

(none) β€” zero parameters, bestie. It’s giving β€œno thoughts, just vibes” πŸ™ˆ


πŸ’– RETURN VALUE πŸ’–

The current element. That’s it, that’s the tea πŸ“


πŸ¦‹ NOTES πŸ¦‹

operator-> is not provided. So don’t go looking for it, okay? 😭


✨ EXAMPLE ✨

// Run this code

#include <iostream>
#include <ranges>
#include <string_view>
#include <tuple>

int main()
{
    using T = std::tuple<int, char, std::string_view>;

    const auto il = {
        T{1, 'A', "Ξ±"},
        T{2, 'B', "Ξ²"},
        T{3, 'C', "Ξ³"},
    };

    const auto view {il | std::views::elements<2>};

    const auto iter {view.begin() + 1};

    std::cout << *iter << '\n';
}

πŸ“ Output πŸ“

Ξ²

πŸ‘‘ SEE ALSO πŸ‘‘

  • operator[] β€” accesses an element by index (C++20) (public member function)

mwah πŸ’‹ β€” source: http://cppreference.com, version/date 2024.06.10, page std::ranges...r::operator*(3). bye bestie, go dereference responsibly 🌈🫢

πŸ“¦ where this page comes from