From cppreference.com
Defined in header
template<ranges::input_rangeV>requiresranges::view<V>andranges::input_range<ranges::range_reference_t<V>>classjoin_view:publicranges::view_interface<join_view<V>> (1) (since C++20)namespaceviews{inlineconstexpr/* unspecified */join=/* unspecified */;} (2) (since C++20)Call signature
template<ranges::viewable_rangeR>requires/* see below */constexprranges::viewautojoin(R&&r);(since C++20)1) A range adaptor that represents
consisting of the sequence obtained from flattening a view of ranges.
join_view models
.
join_view models
when:
ranges::range_reference_t<V> is a reference type, and
V and ranges::range_reference_t<V> each model
.
join_view models
when:
ranges::range_reference_t<V> is a reference type,
V models
, and
ranges::range_reference_t<V> models both
and
.
join_view models
when:
ranges::range_reference_t<V> is a reference type, and
V and ranges::range_reference_t<V> each model
and
.
Member functions
constructs a join_view
(public member function)
returns a copy of the underlying (adapted) view
(public member function)
returns an iterator to the beginning
(public member function)
returns an iterator or a sentinel to the end
(public member function)
Inherited from
returns whether the derived view is empty, provided only if it satisfies
or
(public member function of std::ranges::view_interface<D>)
(C++23)
returns a constant iterator to the beginning of the range
(public member function of std::ranges::view_interface<D>)
(C++23)
returns a sentinel for the constant iterator of the range
(public member function of std::ranges::view_interface<D>)
returns whether the derived view is not empty, provided only if
is applicable to it
(public member function of std::ranges::view_interface<D>)
returns the first element in the derived view, provided if it satisfies
(public member function of std::ranges::view_interface<D>)
returns the last element in the derived view, provided only if it satisfies
and
(public member function of std::ranges::view_interface<D>)
Nested classes
the iterator type
(exposition-only member class template*)the sentinel type
(exposition-only member class template*)Notes
Before
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
of
prvalue.
structPerson{intage;std::stringname;};autof(std::vector<Person>&v){// return v | std::views::transform([](auto& p){ return p.name; })// | std::views::join; // error before P2328R1returnv|std::views::transform([](auto&p)->std::string&{returnp.name;})|std::views::join;// OK}Example
Run this code
#include<iostream>#include<ranges>#include<string_view>#include<vector>intmain(){usingnamespacestd::literals;constautobits={"https:"sv,"//"sv,"cppreference"sv,"."sv,"com"sv};for(charconstc:bits|std::views::join)std::cout<<c;std::cout<<'\n';conststd::vector<std::vector<int>>v{{1,2},{3,4,5},{6},{7,8,9}};autojv=std::ranges::join_view(v);for(intconste:jv)std::cout<<e<<' ';std::cout<<'\n';}Output:
https://cppreference.com 1 2 3 4 5 6 7 8 9 Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
C++20 views::join(e) returned a copy of e when e is a join_viewreturns a nested join_view
C++20 non-view
prvalues could not be joined by join_viewmade joinable See also