std::ranges::elements_view<V,N>::elements_view
来自cppreference.com
< cpp | ranges | elements view
elements_view() requires std::default_initializable<V> = default; |
(1) | (C++20 起) |
constexpr elements_view( V base ); |
(2) | (C++20 起) |
构造 elements_view
。
2) 以 std::move(r) 初始化底层视图。
参数
base | - | 底层视图 |
示例
运行此代码
#include <iostream> #include <ranges> #include <tuple> #include <array> using namespace std::literals; int main() { const std::array<std::tuple<int, char, std::string>, 2> vt { std::tuple{1, 'A', "α"s}, std::tuple{2, 'B', "β"s}, }; [[maybe_unused]] auto empty = std::views::elements<0>; auto ev0 = std::views::elements<0>(vt); auto ev1 = std::views::elements<1>(vt); auto ev2 = std::views::elements<2>(vt); for (auto const& e: ev0) { std::cout << e << ' '; } std::cout << '\n'; for (auto const& e: ev1) { std::cout << e << ' '; } std::cout << '\n'; for (auto const& e: ev2) { std::cout << e << ' '; } std::cout << '\n'; }
输出:
1 2 A B α β