Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::views::concat,std::ranges::concat_view

      From cppreference.com
      <cpp‎ |ranges
       
       
      Ranges library
      Range adaptors
       
      std::ranges::concat_view
      Member functions
      Deduction guides
      Iterator
      Member functions
      Non-member functions
       
      Defined in header<ranges>
      template<ranges::input_range...Views>

          requires(ranges::view<Views>&& ...)&&(sizeof...(Views)>0)&&
                   /*concatable*/<Views...>
      class concat_view

         :publicranges::view_interface<concat_view<Views...>>
      (1)(since C++26)
      namespace views{

         inlineconstexpr/* unspecified */ concat=/* unspecified */;

      }
      (2)(since C++26)
      Call signature
      template<ranges::viewable_range...Rs>

          requires/* see below */

      constexprranges::viewauto concat( Rs&&...rs);
      (since C++26)
      Helper type aliases
      template<class...Rs>

      using/*concat-reference-t*/=

         ranges::common_reference_t<ranges::range_reference_t<Rs>...>;
      (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*/=

         ranges::common_reference_t<ranges::range_rvalue_reference_t<Rs>...>;
      (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.

      1) The class template with a template parameter that is a non-empty pack ofviews each of which models at leastinput_range and isconcatable(7).
      2)views::concat is a customization point object.

      Given a pack of subexpressionsexprs, the expressionviews::concat(exprs...) isexpression-equivalent to

      • views::all(exprs...) ifexprs is a pack with only one element whose type modelsinput_range,
      • concat_view(exprs...) otherwise.
      3) Represents the reference type. An extra constraint is needed to make sure that each underlying range’sranges::range_reference_t is convertible toranges::common_reference_t.
      4) Theiterator::value_type that additionally respects the underlying ranges’value_type to support the cases when the underlying ranges have proxy iterators.
      5) The rvalue reference that also correctly supports the cases where underlying iterators customizeiter_move.
      6) Defines theindirectly-readable concept for theiterator so thatconcat_view can modelinput_range.
      Equivalent to:
      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>>&& ...);
      where exposition-only concept/*concat-indirectly-readable-impl*/ is
      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>;};
      7) Determines whether any two or more different ranges can be adapted into a sequence that itself models a range. Equivalent to:
      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

      Customization point objects

      The nameviews::concat denotes acustomization point object, which is a constfunction object of aliteralsemiregular class type. SeeCustomizationPointObject for details.

      [edit]Data members

      Member Description
      std::tuple<Views...>views_ all adapted view objects
      (exposition-only member object*)

      [edit]Member functions

      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 ofstd::ranges::view_interface<D>)[edit]
      (C++23)
      returns a constant iterator to the beginning of the range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      (C++23)
      returns a sentinel for the constant iterator of the range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns whether the derived view is not empty, provided only ifranges::empty is applicable to it
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns the first element in the derived view, provided if it satisfiesforward_range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns the last element in the derived view, provided only if it satisfiesbidirectional_range andcommon_range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns thenth element in the derived view, provided only if it satisfiesrandom_access_range
      (public member function ofstd::ranges::view_interface<D>)[edit]

      [edit]Deduction guides

      [edit]Nested classes

      Class name Definition
      the iterator type
      (exposition-only member class template*)

      [edit]Helper templates

      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.

      [edit]Notes

      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 macroValueStdFeature
      __cpp_lib_ranges_concat202403L(C++26)std::ranges::concat_view

      [edit]Example

      The preliminary version can be checked out onCompiler Explorer.

      Run this code
      #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]

      [edit]References

      • C++26 standard (ISO/IEC 14882:2026):
      • 26.7.18 Concat view [range.concat]

      [edit]See also

      aview consisting of the sequence obtained from flattening aview ofranges
      (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]
      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]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/concat_view&oldid=177004"

      [8]ページ先頭

      ©2009-2025 Movatter.jp