Namespaces
Variants

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

From cppreference.net
Ranges library
Range adaptors
constexpr auto begin ( ) requires ( ! /*simple_view*/ < V > ) ;
(1) (C++20以降)
constexpr auto begin ( ) const requires range < const V > ;
(2) (C++20以降)
1) common_view の最初の要素へのイテレータを返す。すなわち:
2) (1) と同じですが、 V がconst修飾されています。

目次

戻り値

基になるビューの先頭を指すイテレータ。

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

出力:

1 + 2 + 3 = 6

不具合報告

以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。

DR Applied to Behavior as published Correct behavior
LWG 4012 C++20 non-const overload missed simple-view check added
日本語訳:
問題報告 適用対象 公開時の動作 正しい動作
LWG 4012 C++20 non-constオーバーロードがsimple-viewチェックを欠落 追加済み

関連項目

終端を指すイテレータを返す
(公開メンバ関数)
範囲の先頭を指すイテレータを返す
(カスタマイゼーションポイントオブジェクト)
範囲の終端を示すセンチネルを返す
(カスタマイゼーションポイントオブジェクト)