std::ranges...t_view::base(3)

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

🌸 NAME 🌸

std::ranges::split_view::base β€” std::ranges::split_view::base

Okay bestie, welcome to this little corner of the group chat πŸ’… β€” the page is std::ranges...t_view::base(3), and it lives in the C++ Standard Libary manual (yes, that spelling is literally in the header, not me fixing it β€” iykyk 🫢). This is the std::ranges::split_view::base page, and it's lowkey iconic because it's all about getting a copy of the view underneath. ✨

✨ Synopsis ✨

          constexpr V base() const& requires std::copy_constructible<V>; (1)
       (since C++20)
          constexpr V base() &&;                                         (2)
       (since C++20)

It returns a copy of the underlying view base_ πŸ’–

  1. Copy constructs the result from the underlying view.
  2. Move constructs the result from the underlying view.

πŸŽ€ Parameters πŸŽ€

(none) β€” no parameters, bestie. Not a single one. The vibe check came back empty and that's slay πŸ’…

πŸ¦‹ Return value πŸ¦‹

  1. A copy of the underlying view.
  2. A view move-constructed from the underlying view.

So overload (1) gives you a copy, and overload (2) gives you a move-constructed view. Periodt. πŸ‘‘

πŸ’– Example πŸ’–

Run this code, bestie β€” it's giving main character energy:

       // Run this code

        #include <iomanip>
        #include <iostream>
        #include <ranges>
        #include <string_view>

        int main()
        {
            constexpr std::string_view keywords{"this throw true try typedef
       typeid"};
            std::ranges::split_view split_view{keywords, ' '};
            std::cout << "base() = " << std::quoted(split_view.base()) << "\n"
                         "substrings: ";
            for (auto split : split_view)
                std::cout << std::quoted(std::string_view{split}) << ' ';
            std::cout << '\n';
        }
This is exactly how the keywords line is laid out on the page β€” line break and all β€” so copy-paste carefully, bestie 🫢

⭐ Output ⭐

base() = "this throw true try typedef typeid"
substrings: "this" "throw" "true" "try" "typedef" "typeid"

πŸ™ˆ Defect reports πŸ™ˆ

The following behavior-changing defect reports were applied retroactively to previously published C++ standards:

  • LWG 3590 β€” applied to C++20.
    • Behavior as published: the const& overload additionally required validity of copy-assignment.
    • Correct behavior: constraints relaxed.

πŸ‘‘ See also πŸ‘‘

  • base β€” returns a copy of the underlying (adapted) view (C++20) (public member function of std::ranges::lazy_split_view<V,Pattern>).

That's the whole page, bestie β€” no cap. Big smooch from http://cppreference.com, dated 2024.06.10, page std::ranges...t_view::base(3). Stay constexpr, stay iconic πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from