Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::views::join,std::ranges::join_view

      From cppreference.com
      <cpp‎ |ranges
       
       
      Ranges library
      Range adaptors
       
       
      Defined in header<ranges>
      template<ranges::input_range V>

          requiresranges::view<V> and
                   ranges::input_range<ranges::range_reference_t<V>>
      class join_view

         :publicranges::view_interface<join_view<V>>
      (1)(since C++20)
      namespace views{

         inlineconstexpr/* unspecified */ join=/* unspecified */;

      }
      (2)(since C++20)
      Call signature
      template<ranges::viewable_range R>

          requires/* see below */

      constexprranges::viewauto join( R&& r);
      (since C++20)
      1) A range adaptor that representsview consisting of the sequence obtained from flattening a view of ranges.
      2)RangeAdaptorObject (and alsoRangeAdaptorClosureObject). The expressionviews::join(e) isexpression-equivalent tojoin_view<views::all_t<decltype((e))>>{e} for any suitable subexpressionse.

      join_view modelsinput_range.

      join_view modelsforward_range when:

      join_view modelsbidirectional_range when:

      join_view modelscommon_range when:

      Contents

      [edit]Member functions

      constructs ajoin_view
      (public member function)[edit]
      returns a copy of the underlying (adapted) 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]
      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]

      [edit]Deduction guides

      [edit]Nested classes

      the iterator type
      (exposition-only member class template*)
      the sentinel type
      (exposition-only member class template*)

      [edit]Notes

      BeforeP2328R1 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 atransform_view ofstd::string prvalue.

      struct Person{int age;std::string name;}; auto f(std::vector<Person>& v){//  return v | std::views::transform([](auto& p){ return p.name; })//           | std::views::join; // error before P2328R1return v| std::views::transform([](auto& p)->std::string&{return p.name;})| std::views::join;// OK}

      [edit]Example

      Run this code
      #include <iostream>#include <ranges>#include <string_view>#include <vector> int main(){usingnamespace std::literals; constauto bits={"https:"sv,"//"sv,"cppreference"sv,"."sv,"com"sv};for(charconst c: 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}};auto jv= std::ranges::join_view(v);for(intconst e: jv)std::cout<< e<<' ';std::cout<<'\n';}

      Output:

      https://cppreference.com1 2 3 4 5 6 7 8 9

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3474C++20views::join(e) returned a copy ofe whene is ajoin_viewreturns a nestedjoin_view
      P2328R1C++20non-viewrange prvalues could not be joined byjoin_viewmade joinable

      [edit]See also

      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 concatenation of the adapted views
      (class template)(customization point object)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/join_view&oldid=174150"

      [8]ページ先頭

      ©2009-2025 Movatter.jp