std::ranges...p_while_view(3)

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

πŸ’… std::ranges...p_while_view(3) πŸ’…

okay so this is the std::ranges...p_while_view(3) page from the C++ Standard Libary manual (spelling as printed, bestie β€” we respect the typo 🫢), and we're about to make this constructor make sense. no cap. ✨


🌸 NAME 🌸

  • std::ranges::drop_while_view::drop_while_view β€” std::ranges::drop_while_view::drop_while_view

that's the constructor, and yes it has main character energy and repeats its own name. iconic. πŸ’…

✨ Synopsis ✨

here's the synopsis exactly as printed (formatting is giving very "PDF from 2004" 😭):

          drop_while_view() requires std::default_initializable<V> &&
                                     std::default_initializable<Pred> =
       (1) (since C++20)
          default;
          constexpr explicit drop_while_view( V base, Pred pred );
       (2) (since C++20)

Constructs a drop_while_view. πŸ’–

  1. Default constructor. Value-initializes the underlying view and the predicate.
  2. Move constructs the underlying view from base and the predicate from pred.

πŸŽ€ Parameters πŸŽ€

  • base β€” underlying view
  • pred β€” predicate

πŸ¦‹ Example πŸ¦‹

// Run this code

#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; }
    };

    for (int x : view)
        std::cout << x << ' ';
    std::cout << '\n';
}

πŸ“ Output: πŸ“

3 1 4 1 5

🩹 Defect reports 🩹

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

  • DR LWG 3714 (P2711R1) β€” Applied to: C++20. Behavior as published: the multi-parameter constructor was not explicit. Correct behavior: made explicit.
  • DR P2325R3 β€” Applied to: C++20. Behavior as published: if Pred is not default_initializable, the default constructor constructs a drop_while_view which does not contain an Pred. Correct behavior: the drop_while_view is also not default_initializable.

source/version/date, bestie: http://cppreference.com Β· 2024.06.10 Β· std::ranges...p_while_view(3) β€” mwah, go be default_initializable πŸ’‹

πŸ“¦ where this page comes from