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"; // unspecified }
可能的输出
copy of str: [C++20] view.base(): [C++20] moved str: [C++20] view.base(): []