std::ranges...view::begin(3)

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

okay bestie, welcome to the std::ranges...view::begin(3) page from the C++ Standard Libary manual πŸŽ€ this is the std::ranges::cartesian_product_view::begin entry, and yes the name literally repeats itself, iconic.

✨ NAME ✨

std::ranges::cartesian_product_view::begin β€” std::ranges::cartesian_product_view::begin πŸ’…


πŸŒ€ Synopsis πŸŒ€

          constexpr iterator<false> begin()
       (1) (since C++23)
              requires (!__simple_view<First> || ... || !__simple_view<Vs>);
          constexpr iterator<true> begin() const
              requires (ranges::range<const First> && ... &&
       (2) (since C++23)
          ranges::range<const Vs>);

so there are two begin overloads, both constexpr, both since C++23 ✨ overload (1) has that requires (!__simple_view<First> || ... || !__simple_view<Vs>); constraint, and overload (2) is the const one with the requires (ranges::range<const First> && ... && ranges::range<const Vs>); situation 🫢

Returns an iterator to the first element of the cartesian_product_view.

Let bases_ be the tuple of underlying views.

  1. Equivalent to return /*iterator*/<false>(__tuple_transform(ranges::begin, bases_));.
  2. Equivalent to return /*iterator*/<true>(__tuple_transform(ranges::begin, bases_));.

πŸŽ€ Parameters πŸŽ€

(none) β€” like, literally none. no parameters, no stress 🫢

πŸ’– Return value πŸ’–

An iterator to the first element. periodt πŸ’…

🌈 Example 🌈

       // Run this code

        #include <array>
        #include <format>
        #include <iostream>
        #include <ranges>
        #include <string_view>
        #include <tuple>
        using namespace std::literals;

        int main()
        {
            constexpr auto a = std::array{"Curiously"sv, "Recurring"sv,
       "Template"sv, "Pattern"sv};

            constexpr auto v = std::ranges::cartesian_product_view(a[0], a[1],
       a[2], a[3]);

            constexpr std::tuple<char const&,
                                 char const&,
                                 char const&,
                                 char const&> first{*v.begin()};

            std::cout << std::format("{}{}{}{}{}",
                                     std::get<0>(first),
                                     std::get<1>(first),
                                     std::get<2>(first),
                                     std::get<3>(first),
                                     '\n');
        }

⭐ Output ⭐

CRTP

it's giving CRTP and honestly that's the whole output πŸ”₯

πŸ‘€ See also πŸ‘€

  • end β€” returns an iterator or a sentinel to the end (C++23) (public member function)
  • ranges::begin β€” returns an iterator to the beginning of a range (C++20) (customization point object)

mwah πŸ’‹ β€” this iconic page came from http://cppreference.com, dated 2024.06.10, and it's the std::ranges...view::begin(3) entry in the C++ Standard Libary manual. bye bestie πŸ¦‹

πŸ“¦ where this page comes from