命名空间
变体
操作

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

来自 cppreference.cn
< cpp‎ | ranges‎ | common view
 
 
范围库
范围适配器
 
 
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 应用于 发布时的行为 正确的行为
LWG 4012 C++20 非 const 重载遗漏 simple-view 检查 已添加

[编辑] 参见

返回指向末尾的迭代器
(公有成员函数) [编辑]
返回指向范围开始的迭代器
(定制点对象)[编辑]
返回指示范围末尾的哨位
(定制点对象)[编辑]