std::ranges::common_view<V>::begin

From cppreference.com
< cpp‎ | ranges‎ | common view
 
 
Ranges library
Range access
Range conversions
(C++23)
Range primitives



Dangling iterator handling
Range concepts
Views

Factories






Adaptors
Range adaptor objects
Range adaptor closure objects
Helper items
 
std::ranges::common_view
Member functions
common_view::begin
(C++20)
Deduction guides
 
constexpr auto begin();
(1) (since C++20)
constexpr auto begin() const requires range<const V>;
(2) (since C++20)
1) Returns an iterator to the first element of the common_view, that is: Here base_ (the name is for exposition only purposes) is the underlying view.
2) Same as (1), but V is const-qualified.

Parameters

(none)

Return value

An iterator to the beginning of the underlying view.

Example

#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

See also

(C++20)
returns an iterator to the end
(public member function)
returns an iterator to the beginning of a range
(customization point object)
returns a sentinel indicating the end of a range
(customization point object)