std::ranges...lements_view(3)

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

bestie, welcome to std::ranges...lements_view(3) from the C++ Standard Libary (that spelling is literally in the header, I'm not doing a bits, okay 😭). This whole page is about std::ranges::elements_view::elements_view, and it's giving very constructor with main character energy πŸ’…

πŸŽ€ NAME πŸŽ€

std::ranges::elements_view::elements_view β€” yes, the name said it twice, and honestly? periodt. It's std::ranges::elements_view::elements_view 🫢

✨ Synopsis ✨

okay so here's the synopsis, copied with love and zero cap:

elements_view() requires std::default_initializable<V> = default; (1)
(since C++20)
constexpr explicit elements_view( V base );                       (2)
(since C++20)

This constructs an elements_view πŸ¦‹

  1. Default constructor β€” elements_view() requires std::default_initializable<V> = default; (since C++20). It value-initializes the underlying view. After construction, base() returns a copy of V() ✨
  2. The taking-a-base one β€” constexpr explicit elements_view( V base ); (since C++20). It initializes the underlying view with std::move(base) πŸ’«

🌸 Parameters 🌸

  • base β€” the underlying view 🫢

πŸ“ Example πŸ“

bestie, run this code, it's literally right here:

        // Run this code

        #include <array>
        #include <iostream>
        #include <ranges>
        #include <tuple>

        void println(auto const& v)
        {
            for (auto const& e : v)
                std::cout << e << ' ';
            std::cout << '\n';
        }

        int main()
        {
            using namespace std::literals;

            const std::array<std::tuple<int, char, std::string>, 2> vt
            {
                std::tuple{1, 'A', "Ξ±"s},
                std::tuple{2, 'B', "Ξ²"s},
            };

            [[maybe_unused]]
            auto empty = std::views::elements<0>;

            println(std::views::elements<0>(vt));
            println(std::views::elements<1>(vt));
            println(std::views::elements<2>(vt));
        }

🌈 Output 🌈

and the output is serving:

        1 2
        A B
        Ξ± Ξ²

source: http://cppreference.com Β· version/date: 2024.06.10 β€” that's the whole page, bestie, mwah πŸ’‹

πŸ“¦ where this page comes from