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

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

πŸ’– NAME πŸ’–

std::ranges::drop_while_view::begin β€” okay bestie, this is the std::ranges..._view::begin(3) page from the C++ Standard Libary manual, and it’s literally the begin member of drop_while_view. No cap, it’s giving iterator-to-the-front energy. ✨


✨ Synopsis ✨

constexpr auto begin();  (since C++20)

Returns an iterator to the first element of the view. πŸ’…

Effectively returns ranges::find_if_not(base_, std::cref(pred())), where base_ is the underlying view. The behavior is undefined if *this does not store a predicate. 😭

⚠️ Warning bestie: undefined behavior if *this does not store a predicate. Not a vibe. Keep the predicate stored, fr fr.

In order to provide the amortized constant time complexity required by the range concept, this function caches the result within the drop_while_view object for use on subsequent calls. It’s lowkey doing main character caching so later calls stay fast. πŸ”₯


🌸 Parameters 🌸

(none) β€” literally zero parameters, bestie. Nothing. Nada. 🫢


πŸŽ€ Return value πŸŽ€

Iterator to the first element of the view. Periodt. πŸ‘‘


πŸ¦‹ Example πŸ¦‹

Run this code, bestie πŸ‘‡

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

int main()
{
    constexpr std::array data{ 0, -1, -2, 3, 1, 4, 1, 5 };

    auto view = std::ranges::drop_while_view{
        data, [](int x) { return x <= 0; }
    };

    std::cout << *view.begin() << '\n';
}

🌈 Output 🌈

3

πŸ‘€ See also πŸ‘€

  • end β€” returns an iterator or a sentinel to the end (C++20) (public member function) πŸ’œ

Source/version: http://cppreference.com Β· date: 2024.06.10 β€” bye bestie, go slay those ranges πŸ§šπŸ’–πŸŽ€

πŸ“¦ where this page comes from