std::ranges...t_view::base(3)
πΈ 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_ π
- Copy constructs the result from the underlying view.
- 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 π¦
- A copy of the underlying view.
- 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.
- Behavior as published: the
π See also π
baseβ returns a copy of the underlying (adapted) view (C++20) (public member function ofstd::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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms