std::ranges::common_view<V>::end

来自cppreference.com
< cpp‎ | ranges‎ | common view
 
 
范围库
范围适配器
 
 
constexpr auto end() requires (!/*simple-view*/<V>);
(1)(C++20 起)
constexpr auto end() const requires ranges::range<const V>;
(2)(C++20 起)
1) 返回表示 common_view 末尾的迭代器,即:
2)(1),但 V 为 const 限定。

返回值

表示底层视图末尾的迭代器。

示例

#include <iostream>
#include <numeric>
#include <ranges>
 
int main()
{
    constexpr int n{4};
 
    constexpr auto cv1 = std::views::iota(1)
                       | std::views::take(n)
                       | std::views::common
                       ;
    constexpr auto cv2 = std::views::iota(2)
                       | std::views::take(n)
                       ;
    const int product = std::inner_product(cv1.begin(), cv1.end(), 
                                           cv2.begin(),
                                           0);
    std::cout << product << '\n';
}

输出:

40

缺陷报告

下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。

缺陷报告应用于出版时的行为正确行为
LWG 4012C++20非 const 重载缺少对简单视图的检查已添加

参阅

返回指向起始的迭代器
(公开成员函数)
返回指向范围起始的迭代器
(定制点对象)
返回指示范围结尾的哨位
(定制点对象)