std::ranges::take_while_view<V,Pred>::base

来自cppreference.com
 
 
范围库
范围适配器
 
 
constexpr V base() const& requires std::copy_constructible<V>;
(1) (C++20 起)
constexpr V base() &&;
(2) (C++20 起)

返回底层视图的副本。

1) 从底层视图 base_ 复制构造结果。
2) 从底层视图 base_ 移动构造结果。

参数

(无)

返回值

底层范围的副本。

示例

#include <iostream>
#include <ranges>
 
namespace stq {
void println(auto, const auto& v)
{
    for (const auto& e : v)
        std::cout << e << ' ';
    std::cout << '\n';
}
}
 
int main()
{
    static constexpr int a[]{1, 2, 3, 4, 5};
    constexpr auto view = a | std::views::take_while([](int x){ return x < 4; });
    stq::println("{}", view);
    const auto base = view.base();
    stq::println("{}", base);
}

输出:

1 2 3
1 2 3 4 5