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

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

πŸ’… std::ranges..._view::begin(3) πŸ’…

okay so bestie, this is the C++ Standard Libary manual page β€” yes, that spelling is straight from the header and we’re keeping it πŸ’–. The header title is std::ranges..._view::begin(3), and the NAME section is literally std::ranges::common_view::begin twice. Iconic repetition, no notes.

🌸 NAME 🌸

std::ranges::common_view::begin β€” std::ranges::common_view::begin

That’s the whole NAME, fr fr. The manual name folded up top is C++ Standard Libary, section 3.


✨ Synopsis ✨

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

Both overloads are marked since C++20. The synopsis is giving overload energy, and we’re obsessed.

  1. Returns an iterator to the first element of the common_view, that is:
    • ranges::begin(base_), if both ranges::random_access_range<V> and ranges::sized_range<V> are satisfied,
    • std::common_iterator<ranges::iterator_t<V>, ranges::sentinel_t<V>>(ranges::begin(base_)) otherwise.

Here base_ (the name is for exposition only purposes) is the underlying view.

  1. Same as (1), but V is const-qualified.

🧚 Parameters 🧚

None. Not a single parameter. Periodt.

πŸŽ€ Return value πŸŽ€

An iterator to the beginning of the underlying view.

πŸ“ Example πŸ“

Run this code, bestie β€” it’s right here, untouched:

// Run this code

#include <iostream>
#include <numeric>
#include <ranges>
#include <string_view>

int main()
{
    constexpr auto common = std::views::iota(1)
                          | std::views::take(3)
                          | std::views::common
                          ;

    for (int i{}; int e : common)
        std::cout << (i++ ? " + " : "") << e;

    std::cout << " = " << std::accumulate(common.begin(), common.end(),
0) << '\n';
}

πŸ“ Output πŸ“

1 + 2 + 3 = 6

πŸ’€ Defect reports πŸ’€

The following behavior-changing defect reports were applied retroactively to previously published C++ standards. Retroactive fixes are lowkey iconic.

  • LWG 4012 β€” Applied to: C++20; Behavior as published: non-const overload missed simple-view check; Correct behavior: added.

πŸ¦‹ See also πŸ¦‹

  • end (C++20) β€” returns an iterator to the end (public member function)
  • ranges::begin (C++20) β€” returns an iterator to the beginning of a range (customization point object)
  • ranges::end (C++20) β€” returns a sentinel indicating the end of a range (customization point object)

🌈 xoxo, bestie 🌈 β€” source: http://cppreference.com; version/date: 2024.06.10; footer title: std::ranges..._view::begin(3). Stay iconic, and hydrate before you compile πŸ’…πŸ’–

πŸ“¦ where this page comes from