A range adaptor that represents
view
consisting of the sequence obtained from flattening a view of ranges.
join_view
models input_range
.
join_view
models forward_range
when:
forward_range
.join_view
models bidirectional_range
when:
bidirectional_range
, andbidirectional_range
and common_range
.join_view
models common_range
when:
forward_range
and common_range
.join_view
sized_range
or forward_range
std::ranges::view_interface<D>
) [edit] returns a constant iterator to the beginning of the range
std::ranges::view_interface<D>
) [edit] returns a sentinel for the constant iterator of the range
std::ranges::view_interface<D>
) [edit] returns whether the derived view is not empty, provided only if ranges::empty is applicable to it
std::ranges::view_interface<D>
) [edit] returns the first element in the derived view, provided if it satisfies forward_range
std::ranges::view_interface<D>
) [edit] returns the last element in the derived view, provided only if it satisfies bidirectional_range
and common_range
std::ranges::view_interface<D>
) [edit] [edit] Deduction guides [edit] Nested classes the iterator type
Before P2328R1 was adopted, the inner range type (ranges::range_reference_t<V>) cannot be a container type (but can be reference to container). For example, it was not allowed to join a transform_view
of std::string prvalue.
struct Person { int age; std::string name; }; auto f(std::vector<Person>& v) { // return v | std::views::transform([](auto& p){ return p.name; }) // | std::views::join; // error before P2328R1 return v | std::views::transform([](auto& p) -> std::string& { return p.name; }) | std::views::join; // OK }[edit] Example
#include <iostream> #include <ranges> #include <string_view> #include <vector> int main() { using namespace std::literals; const auto bits = {"https:"sv, "//"sv, "cppreference"sv, "."sv, "com"sv}; for (char const c : bits | std::views::join) std::cout << c; std::cout << '\n'; const std::vector<std::vector<int>> v{{1, 2}, {3, 4, 5}, {6}, {7, 8, 9}}; auto jv = std::ranges::join_view(v); for (int const e : jv) std::cout << e << ' '; std::cout << '\n'; }
Output:
https://cppreference.com 1 2 3 4 5 6 7 8 9[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 3474 C++20 views::join(e) returned a copy of e when e is ajoin_view
returns a nested join_view
P2328R1 C++20 non-view range
prvalues could not be joined by join_view
made joinable [edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4