std::ranges::common_view<V>::base

来自cppreference.com
< cpp‎ | ranges‎ | common view
 
 
 
 
constexpr V base() const& requires std::copy_constructible<V>;
(1) (C++20 起)
constexpr V base() &&;
(2) (C++20 起)

返回底层视图的副本。

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

参数

(无)

返回值

底层视图的副本。

示例

#include <iostream>
#include <ranges>
#include <string>
 
int main()
{
    std::string str { "C++20" };
    auto view = std::views::common(str);
 
    std::string copy_of_str = view.base();
    std::cout << "copy of str: [" << copy_of_str << "]\n";
    std::cout << "view.base(): [" << view.base() << "]\n";
 
    std::string move_str = std::move(view.base());
    std::cout << "moved str:   [" << move_str << "]\n";
    std::cout << "view.base(): [" << view.base() << "]\n"; // 未指定
}

可能的输出:

copy of str: [C++20]
view.base(): [C++20]
moved str:   [C++20]
view.base(): []