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

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

πŸŽ€ std::ranges::take_while_view::begin πŸŽ€

okay so bestie, this is the C++ Standard Libary manual page for std::ranges::take_while_view::begin β€” and the header labels the page std::ranges..._view::begin(3) (yes, with the ellipsis, we love an abbreviated moment πŸ’…). It’s giving C++20 ranges energy, and we’re gonna get through every detail together, no cap.

πŸ’– NAME πŸ’–

std::ranges::take_while_view::begin - std::ranges::take_while_view::begin

🌸 Synopsis 🌸

Here’s the synopsis, verbatim, because we do not mess with code in this group chat:

          constexpr auto begin() requires (!__SimpleView<V>);
       (1) (since C++20)
          constexpr auto begin() const requires

              ranges::range<const V> &&
       (2) (since C++20)

              std::indirect_unary_predicate<const Pred,
          ranges::iterator_t<const V>>;

Overload (1) is the non-const one, and it does not participate in overload resolution if V is a simple view (that is, if V and const V are views with the same iterator and sentinel types). Overload (2) is the const one, with the constraints right there in the signature β€” ranges::range<const V> and std::indirect_unary_predicate<const Pred, ranges::iterator_t<const V>>, periodt. Both are constexpr auto begin(), both are (since C++20), and both are iconic πŸ’….

🐚 Parameters 🐚

Parameters: none. Zero. Nada. Nothing to pass in, bestie 🫢.

✨ Return value ✨

ranges::begin(base_), where base_ is the underlying view. That’s the whole return value, and it ate πŸ’….

Also, to be clear: begin() returns an iterator to the first element of the view. Effectively, it calls ranges::begin on the underlying view. Lowkey elegant, highkey useful.

πŸ“ Example πŸ“

This section is incomplete. Reason: no example. Literally no example here, so no demo to slay with 😭. (The page is not hiding one; it just says no example.)

πŸ”₯ Defect reports πŸ”₯

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

  • DR: LWG 3450
  • Applied to: C++20
  • Behavior as published: the const overload might return an iterator non-comparable to the sentinel
  • Correct behavior: constrained

So yeah, that’s the defect-report tea: LWG 3450, applied to C++20, and the published behavior was that the const overload might return an iterator non-comparable to the sentinel. The correct behavior is constrained. Not me reading defect reports for fun… okay maybe me πŸ™ˆ.

πŸ¦‹ See also πŸ¦‹

  • end (C++20) β€” returns a sentinel representing the end (public member function)
  • operator== (C++20) β€” compares a sentinel with an iterator returned from take_while_view::begin (function)

🏷️ Category 🏷️

Category: * Todo no example


xoxo πŸ’‹ source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::ranges..._view::begin(3)

πŸ“¦ where this page comes from