std::ranges...view::begin(3)
π¦ NAME π¦
std::ranges::split_view::begin β std::ranges::split_view::begin π
okay so bestie, you're on the std::ranges...view::begin(3) page from the C++ Standard Libary manual, and we are about to understand this iterator like the main character she is β¨
π Synopsis π
constexpr /*iterator*/ begin(); (since C++20)
Returns an iterator to the first found subrange. no cap π«Ά
In order to provide the amortized constant time complexity required by the range concept, this function caches the result within the split_view for use on subsequent calls. It's equivalent to:
constexpr /*iterator*/ begin()
{
if (!cached_begin_.has_value())
cached_begin_ = this->find_next(ranges::begin(base_));
return {*this, ranges::begin(base_), cached_begin_.value()};
}
The exposition-only data members base_ and cached_begin_ are described here. π
πΈ Parameters πΈ
- (none) β literally no parameters, she takes no notes π
π Return value π
An iterator. That's it. That's the tea. β¨
π₯ Complexity π₯
Amortized \(\scriptsize \mathcal{O}(1)\)O(1). slay. π
π Example π
// Run this code
#include <iomanip>
#include <iostream>
#include <ranges>
#include <string_view>
int main()
{
constexpr std::string_view sentence{"Keep..moving..forward.."};
constexpr std::string_view delim{".."};
std::ranges::split_view words{sentence, delim};
std::cout << "begin(): " <<
std::quoted(std::string_view{*words.begin()})
<< "\nSubstrings: ";
for (std::string_view word : words)
std::cout << std::quoted(word) << ' ';
std::ranges::split_view letters{sentence, std::string_view{""}};
std::cout << "\nbegin(): " <<
std::quoted(std::string_view{*letters.begin()})
<< "\nLetters: ";
for (std::string_view letter : letters)
std::cout << letter << ' ';
std::cout << '\n';
}
π Output: π
begin(): "Keep"
Substrings: "Keep" "moving" "forward" ""
begin(): "K"
Letters: K e e p . . m o v i n g . . f o r w a r d . .
π«Ά See also π«Ά
end(C++20) β returns an iterator or a sentinel to the end (public member function) πbegin(C++20) β returns an iterator to the beginning (public member function ofstd::ranges::lazy_split_view<V,Pattern>) β¨ranges::begin(C++20) β returns an iterator to the beginning of a range (customization point object) π«Ά
later babes π this iconic little page comes from source/version http://cppreference.com, dated 2024.06.10, and it's the std::ranges...view::begin(3) page β mwah πβ¨
π¦ 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