std::ranges::views::join_with, std::ranges::join_with_view
Defined in header <ranges> |
||
---|---|---|
template< ranges::input_range V, ranges::forward_range Pattern > requires ranges::view<V> && ranges::input_range<ranges::range_reference_t<V>> && ranges::view<Pattern> && /* range_reference_t<V> and Pattern have compatible elements (see below) */ class join_with_view : ranges::view_interface<join_with_view<V, Pattern>> |
(1) | (since C++23) |
namespace views { inline constexpr /*unspecified*/ join_with = /*unspecified*/; } |
(2) | (since C++23) |
Call signature | ||
template< ranges::viewable_range R, class Pattern > requires /* see below */ constexpr ranges::view auto join_with( R&& r, Pattern&& pattern ); |
(since C++23) | |
template< class Pattern > constexpr /* range adaptor closure */ join_with( Pattern&& pattern ); |
(since C++23) |
1) A range adaptor that represents
view
consisting of the sequence obtained from flattening a view of ranges, with every element of the delimiter inserted in between elements of the view. The delimiter can be a single element or a view of elements.
2)
Range adaptor object. The expression
views::join_with(e, f)
is
expression-equivalent to
join_with_view(e, f)
for any suitable subexpressions
e
and
f
.
ranges::range_reference_t<V>
and Pattern
have compatible elements if, let Inner
denote ranges::range_reference_t<V>
, all of the following concepts are modeled:
-
std::common_with<range_value_t<Inner>, range_value_t<Pattern>>
-
std::common_reference_with<range_reference_t<Inner>, range_reference_t<Pattern>>
-
std::common_reference_with<range_rvalue_reference_t<Inner>, range_rvalue_reference_t<Pattern>>
join_with_view
models input_range
.
join_with_view
models forward_range
when:
-
ranges::range_reference_t<V>
is a reference, and -
V
andranges::range_reference_t<V>
each modelforward_range
.
join_with_view
models bidirectional_range
when:
-
ranges::range_reference_t<V>
is a reference, -
V
,ranges::range_reference_t<V>
, andPattern
each modelsbidirectional_range
, and -
ranges::range_reference_t<V>
andPattern
each modelcommon_range
.
join_with_view
models common_range
when:
-
ranges::range_reference_t<V>
is a reference, -
V
andranges::range_reference_t<V>
each modelforward_range
andcommon_range
.
Expression-equivalent
Expression e
is expression-equivalent to expression f
, if.
-
e
andf
have the same effects, and - either both are constant subexpressions or else neither is a constant subexpression, and
- either both are potentially-throwing or else neither is potentially-throwing (i.e.
noexcept(e) == noexcept(f)
).
Member functions
(C++23)
|
constructs a join_with_view (public member function) |
(C++23)
|
returns a copy of the underlying (adapted) view (public member function) |
(C++23)
|
returns an iterator to the beginning (public member function) |
(C++23)
|
returns an iterator or a sentinel to the end (public member function) |
Inherited from |
|
(C++20)
|
Returns whether the derived view is empty. Provided if it satisfies forward_range . (public member function of std::ranges::view_interface<D> ) |
(C++20)
|
Returns whether the derived view is not empty. Provided if ranges::empty is applicable to it. (public member function of std::ranges::view_interface<D> ) |
(C++20)
|
Returns the first element in the derived view. Provided if it satisfies forward_range . (public member function of std::ranges::view_interface<D> ) |
(C++20)
|
Returns the last element in the derived view. Provided if it satisfies bidirectional_range and common_range . (public member function of std::ranges::view_interface<D> ) |
Deduction guides
Nested classes
(C++23)
|
the iterator type (exposition-only member class template) |
(C++23)
|
the sentinel type (exposition-only member class template) |
Example
#include <iostream> #include <ranges> #include <vector> #include <string_view> int main() { using namespace std::literals; std::vector v{"This"sv, "is"sv, "a"sv, "test."sv}; auto joined = v | std::views::join_with(' '); for (auto c : joined) std::cout << c; std::cout << '\n'; }
Output:
This is a test.
See also
(C++20)
|
a view consisting of the sequence obtained from flattening a view of range s (class template) (range adaptor object) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/ranges/join_with_view