std::ranges...in_with_view(3)
π std::ranges::views::join_with, std::ranges::join_with_view π
Okay bestie, welcome to the std::ranges...in_with_view(3) page from the C++ Standard Libary manual β yes, Libary with one r, that's how it's spelled here, no cap π β and it's all about the join_with duo: std::ranges::views::join_with,std::ranges::join_with_view. Let's go. π
πΈ NAME πΈ
std::ranges::views::join_with, std::ranges::join_with_view β that's the name, that's the whole assignment, and also the exact pair this page is serving. β¨
π Synopsis π
Defined in header <ranges>.
(1) (since C++23)
template< ranges::input_range V, ranges::forward_range Pattern >
requires ranges::view<V> and
ranges::input_range<ranges::range_reference_t<V>> and
ranges::view<Pattern> and
/* ranges::range_reference_t<V> and Pattern
have compatible elements (see below) */
class join_with_view
: ranges::view_interface<join_with_view<V, Pattern>>
(2) (since C++23)
namespace views {
inline constexpr /* unspecified */ join_with = /* unspecified */;
}
Call signature
Both of these are (since C++23):
template< ranges::viewable_range R, class Pattern >
requires /* see below */
constexpr ranges::view auto join_with( R&& r, Pattern&& pattern );
template< class Pattern >
constexpr /* range adaptor closure */ join_with( Pattern&& pattern );
- A range adaptor that represents a 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. π«Ά
RangeAdaptorObject. The expressionviews::join_with(e, f)is expression-equivalent tojoin_with_view(e, f)for any suitable subexpressionseandf.
ranges::range_reference_t<V> and Pattern have compatible elements if all of the following concepts are modeled:
std::common_with<ranges::range_value_t<ranges::range_reference_t<V>>, ranges::range_value_t<Pattern>>std::common_reference_with<ranges::range_reference_t<ranges::range_reference_t<V>>, ranges::range_reference_t<Pattern>>std::common_reference_with<ranges::range_rvalue_reference_t<ranges::range_reference_t<V>>, ranges::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, andVandranges::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>, andPatterneach modelsbidirectional_range, andranges::range_reference_t<V>andPatterneach modelcommon_range.
join_with_view models common_range when:
ranges::range_reference_t<V>is a reference, andVandranges::range_reference_t<V>each modelforward_rangeandcommon_range.
π οΈ Member functions π οΈ
- constructor (C++23) β constructs a
join_with_view(public member function) base(C++23) β returns a copy of the underlying (adapted) view (public member function)begin(C++23) β returns an iterator to the beginning (public member function)end(C++23) β returns an iterator or a sentinel to the end (public member function)
π« Inherited from std::ranges::view_interface π«
empty(C++20) β returns whether the derived view is empty. Provided if it satisfiessized_rangeorforward_range. (public member function ofstd::ranges::view_interface<D>)cbegin(C++23) β returns a constant iterator to the beginning of the range. (public member function ofstd::ranges::view_interface<D>)cend(C++23) β returns a sentinel for the constant iterator of the range. (public member function ofstd::ranges::view_interface<D>)operator bool(C++20) β returns whether the derived view is not empty. Provided ifranges::emptyis applicable to it. (public member function ofstd::ranges::view_interface<D>)front(C++20) β returns the first element in the derived view. Provided if it satisfiesforward_range. (public member function ofstd::ranges::view_interface<D>)back(C++20) β returns the last element in the derived view. Provided if it satisfiesbidirectional_rangeandcommon_range. (public member function ofstd::ranges::view_interface<D>)
π§ Deduction guides π§
This section is literally just the phrase Deduction guides β no extra bullets here, so we move on with our lives. π«Ά
πͺ Nested classes πͺ
iterator(C++23) β the iterator type (exposition-only member class template*)sentinel(C++23) β the sentinel type (exposition-only member class template*)
π Example π
// Run this code
#include <iostream>
#include <ranges>
#include <string_view>
#include <vector>
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 π
ranges::join_view,views::join(C++20) β a view consisting of the sequence obtained from flattening a view of ranges;ranges::join_viewis the class template, andviews::joinis the range adaptor object.
And that's the tea, bestie! π
This page's footer says source/version/date: http://cppreference.com, 2024.06.10, and the page id is std::ranges...in_with_view(3). Catch you in the next range adaptor. π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms