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

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

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

okay so welcome to the C++ Standard Libary manual β€” yep, "Libary" is the spelling right there in the manual name, no cap 😭 β€” and this page is the whole vibe for std::ranges::zip_transform_view::iterator::operator[].


πŸ’… NAME πŸ’…

std::ranges::zip_transform_view::iterator::operator[] β€” that's the name, bestie. The page literally lists it as:

  • std::ranges::zip_transform_view::iterator::operator[]
  • std::ranges::zip_transform_view::iterator::operator[]

so yeah, it's giving "same thing twice" but that's what the manual says 🫢


πŸ“œ Synopsis πŸ“œ

Here's the signature, copied exactly so you can trust it:

          constexpr decltype(auto) operator[]( difference_type n ) const
       (since C++23)
              requires ranges::random_access_range<Base>;

So it's constexpr, it returns decltype(auto), it takes a difference_type n, it's const, it's since C++23, and there's a requires clause: ranges::random_access_range<Base> ✨

It returns the element at the specified relative location, after transformation. Slay.

It's equivalent to this exact code right here:

        return
            std::apply
            (
                [&]<class... Is>(const Is&... iters) -> decltype(auto)
                {
                    return std::invoke(*parent_->fun_,
       iters[std::iter_difference_t<Is>(n)]...);
                },
                inner_.current_
            );

where *parent_->fun_ is the transformation function of type F stored in the parent ranges::zip_transform_view, and current_ is the underlying tuple of iterators into Views.... iykyk πŸ’–


πŸŽ€ Parameters πŸŽ€

  • n β€” position relative to current location. That's the whole parameter list, periodt.

🌈 Return value 🌈

The element which is the result of transformation (mapping). That's the return value, fr fr.


⚠️ Notes ⚠️

The behavior is undefined if the parent_ pointer to parent ranges::zip_transform_view is null (e.g. if *this is default constructed). bestie please do not default-construct this and then call it, that's not the move πŸ˜­πŸ’€

πŸ§ͺ Example πŸ§ͺ

This section is incomplete.

Reason: no example.

Yeah, the page itself says that. Not me being lazy, I prom πŸ’…


🏷️ Category 🏷️

  • * Todo no example

πŸ’– okay final sign-off: source/version/date is http://cppreference.com Β· 2024.06.10 Β· page std::ranges...::operator[](3) β€” we out, bestie! 🫢🌸

πŸ“¦ where this page comes from