|
Range primitives | |||||||
|
Range concepts | |||||||||||||||||||
|
Range factories | |||||||||
|
Range adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
Helper items | |||||||||||||||||
|
Defined in header <ranges> | ||
template<ranges::input_range...Views> requires(ranges::view<Views>&& ...)&&(sizeof...(Views)>0)&& | (1) | (since C++26) |
namespace views{ inlineconstexpr/* unspecified */ concat=/* unspecified */; | (2) | (since C++26) |
Call signature | ||
template<ranges::viewable_range...Rs> requires/* see below */ | (since C++26) | |
Helper type aliases | ||
template<class...Rs> using/*concat-reference-t*/= | (3) | (exposition only*) |
template<class...Rs> using/*concat-value-t*/=std::common_type_t<ranges::range_value_t<Rs>...>; | (4) | (exposition only*) |
template<class...Rs> using/*concat-rvalue-reference-t*/= | (5) | (exposition only*) |
Helper concepts | ||
template<class Ref,class RRef,class It> concept/*concat-indirectly-readable-impl*/=/* see description */; | (6) | (exposition only*) |
template<class...Rs> concept/*concatable*/=/* see description */; | (7) | (exposition only*) |
concat_view
presents aview
factory that takes an arbitrary number of ranges as an argument list, and provides a view that starts at the first element of the first range, ends at the last element of the last range, with all range elements sequenced in between respectively in the order given in the arguments, effectively concatenating, or chaining together the argument ranges.
view
s each of which models at leastinput_range
and isconcatable
(7).views::concat
is a customization point object.Given a pack of subexpressionsexprs, the expressionviews::concat(exprs...) isexpression-equivalent to
input_range
,iterator::value_type
that additionally respects the underlying ranges’value_type
to support the cases when the underlying ranges have proxy iterators.iter_move
.template<class...Rs>concept/*concat-indirectly-readable*/=// exposition onlystd::common_reference_with</*concat-reference-t*/<Rs...>&&,/*concat-value-t*/<Rs...>&>&&std::common_reference_with</*concat-reference-t*/<Rs...>&&,/*concat-rvalue-reference-t*/<Rs...>&&>&&std::common_reference_with</*concat-rvalue-reference-t*/<Rs...>&&,/*concat-value-t*/<Rs...>const&>&&(/*concat-indirectly-readable-impl*/</*concat-reference-t*/<Rs...>,/*concat-rvalue-reference-t*/<Rs...>,ranges::iterator_t<Rs>>&& ...);
template<class Ref,class RRef,class It>concept/*concat-indirectly-readable-impl*/=// exposition only requires(const It it){{*it}->std::convertible_to<Ref>;{ranges::iter_move(it)}->std::convertible_to<RRef>;};
template<class...Rs>concept/*concatable*/= requires{// exposition onlytypename/*concat-reference-t*/<Rs...>;typename/*concat-value-t*/<Rs...>;typename/*concat-rvalue-reference-t*/<Rs...>;}&&/*concat-indirectly-readable*/<Rs...>;
concat_view
always modelsinput_range
, and modelsforward_range
,bidirectional_range
,random_access_range
, orsized_range
if each adaptedview
type models the corresponding concept.
concat_view
can becommon_range
if the last underlying range modelscommon_range
.
Contents |
The nameviews::concat
denotes acustomization point object, which is a constfunction object of aliteralsemiregular
class type. SeeCustomizationPointObject for details.
Member | Description |
std::tuple<Views...>views_ | all adapted view objects (exposition-only member object*) |
constructs aconcat_view (public member function)[edit] | |
returns an iterator to the beginning (public member function)[edit] | |
returns an iterator or a sentinel to the end (public member function)[edit] | |
returns the number of elements, provided only if the underlying (adapted) range satisfiessized_range (public member function)[edit] | |
Inherited fromstd::ranges::view_interface | |
returns whether the derived view is empty, provided only if it satisfiessized_range orforward_range (public member function of std::ranges::view_interface<D> )[edit] | |
(C++23) | returns a constant iterator to the beginning of the range (public member function of std::ranges::view_interface<D> )[edit] |
(C++23) | returns a sentinel for the constant iterator of the range (public member function of std::ranges::view_interface<D> )[edit] |
returns whether the derived view is not empty, provided only ifranges::empty is applicable to it (public member function of std::ranges::view_interface<D> )[edit] | |
returns the first element in the derived view, provided if it satisfiesforward_range (public member function of std::ranges::view_interface<D> )[edit] | |
returns the last element in the derived view, provided only if it satisfiesbidirectional_range andcommon_range (public member function of std::ranges::view_interface<D> )[edit] | |
returns then th element in the derived view, provided only if it satisfiesrandom_access_range (public member function of std::ranges::view_interface<D> )[edit] |
Class name | Definition |
the iterator type (exposition-only member class template*) |
There is no specialization ofranges::enable_borrowed_range forconcat_view
, because this would require the iterator implementation to contain a copy of all iterators and sentinels of all underlying ranges at all times.
No argumentviews::concat() is ill-formed, because there is no reasonable way to determine an element typeT
. Single argumentviews::concat(r) is expression equivalent toviews::all(r).
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_ranges_concat | 202403L | (C++26) | std::ranges::concat_view |
The preliminary version can be checked out onCompiler Explorer.
#include <cassert>#include <list>#include <print>#include <ranges>#include <vector> int main(){std::vector<int> v0{1,2,3}, v1{4,5};int a[]{6,7};int i{8};auto ie{std::views::single(i)}; auto con= std::views::concat(v0, v1, a, ie);assert(con.size()== v0.size()+ v1.size()+std::size(a)+ ie.size());std::println("con.size(): {}", con.size());std::println("con: {}", con); con[6]=42;// con is random_access_range, operator[] returns a referenceassert(a[1]==42);// a[1] was modified via con[6]std::println("con: {}", con); std::list<int> l{7,8};// list is bidirectional rangeauto cat= std::views::concat(v0, l);std::println("cat: {}", cat);// cat[0] = 13; // compile-time error: cat is bidirectional => no operator[]}
Output:
con.size(): 8con: [1, 2, 3, 4, 5, 6, 7, 8]con: [1, 2, 3, 4, 5, 6, 42, 8]cat: [1, 2, 3, 7, 8]
(C++20) | aview consisting of the sequence obtained from flattening aview ofrange s(class template)(range adaptor object)[edit] |
aview consisting of the sequence obtained from flattening a view of ranges, with the delimiter in between elements(class template)(range adaptor object)[edit] | |
(C++23) | aview consisting of tuples of references to corresponding elements of the adapted views(class template)(customization point object)[edit] |
aview consisting of tuples of results calculated by the n-ary cartesian product of the adapted views(class template)(customization point object)[edit] |