Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::views::cartesian_product,std::ranges::cartesian_product_view

      From cppreference.com
      <cpp‎ |ranges
       
       
      Ranges library
      Range adaptors
      cartesian_product_viewviews::cartesian_product
      (C++23)(C++23)

       
      std::ranges::cartesian_product_view
      Member functions
      Deduction guides
      Iterator
      Member functions
      Non-member functions
       
      Defined in header<ranges>
      template<ranges::input_range First,ranges::forward_range...Vs>

          requires(ranges::view<First>&& ...&&ranges::view<Vs>)
      class cartesian_product_view

         :publicranges::view_interface<cartesian_product_view<First, Vs...>>
      (1)(since C++23)
      namespace views{

         inlineconstexpr/*unspecified*/ cartesian_product=/*unspecified*/;

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

          requires/* see below */

      constexprranges::viewauto cartesian_product( Rs&&...rs);
      (since C++23)
      Helper concepts
      template<bool Const,class First,class...Vs>

      concept/*cartesian-product-is-random-access*/=
         (ranges::random_access_range</*maybe-const*/<Const, First>>&& ...&&
             (ranges::random_access_range</*maybe-const*/<Const, Vs>>&&

                 ranges::sized_range</*maybe-const*/<Const, Vs>>));
      (3)(exposition only*)
      template<class R>

      concept/*cartesian-product-common-arg*/=
         ranges::common_range<R>||

             (ranges::sized_range<R>&&ranges::random_access_range<R>);
      (4)(exposition only*)
      template<bool Const,class First,class...Vs>

      concept/*cartesian-product-is-bidirectional*/=
         (ranges::bidirectional_range</*maybe-const*/<Const, First>>&& ...&&
             (ranges::bidirectional_range</*maybe-const*/<Const, Vs>>&&

                 /*cartesian-product-common-arg*/</*maybe-const*/<Const, Vs>>));
      (5)(exposition only*)
      template<class First,class...Vs>

      concept/*cartesian-product-is-common*/=

         /*cartesian-product-common-arg*/<First>;
      (6)(exposition only*)
      template<class...Vs>

      concept/*cartesian-product-is-sized*/=

         (ranges::sized_range<Vs>&& ...);
      (7)(exposition only*)
      template<bool Const,template<class>class FirstSent,class First,class...Vs>

      concept/*cartesian-is-sized-sentinel*/=
         (std::sized_sentinel_for<FirstSent</*maybe-const*/<Const, First>>,
             ranges::iterator_t</*maybe-const*/<Const, First>>>&& ...&&
                 (ranges::sized_range</*maybe-const*/<Const, Vs>>&&
                     std::sized_sentinel_for<ranges::iterator_t<
                         /*maybe-const*/<Const, Vs>>,

                             ranges::iterator_t</*maybe-const*/<Const, Vs>>>));
      (8)(exposition only*)
      Helper function templates
      template</*cartesian-product-common-arg*/ R>

      constexprauto/*cartesian-common-arg-end*/( R& r)
      {
         ifconstexpr(ranges::common_range<R>)
             returnranges::end(r);
         else
             returnranges::begin(r)+ranges::distance(r);

      }
      (9)(exposition only*)
      1)cartesian_product_view is a range adaptor that takesnviews, wheren > 0, and produces aview of tuples calculated by then-ary cartesian product of the provided ranges. The size of produced view is a multiple of sizes of provided ranges, while each element is a tuple (of references) of the sizen.
      2)views::cartesian_product is a customization point object.
      3) Determines ifcartesian_product is a random access range (see alsorandom_access_range).
      4) Determines ifcartesian_product is a common range (see alsocommon_range).
      5) Determines ifcartesian_product is a bidirectional range (see alsobidirectional_range).
      6) Determines ifcartesian_product satisfies the helper concept/*cartesian-product-is-common*/ (see alsocommon_range).
      7) Determines ifcartesian_product is a sized range (see alsosized_range).
      8) Determines ifcartesian_product uses sized sentinel.
      9) Returns the end of the producedview. Participates in overload resolution only ifcartesian_product satisfies the helper concept/*cartesian-product-common-arg*/.

      TheFirstrange passed tocartesian_product_view is treated specially, since it is only passed through a single time. As a result, several constrains are relaxed on it:

      Contents

      Customization point objects

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

      [edit]Data members

      Member Definition
      std::tuple<First, Vs...>base_(private) An object that holds all adaptedview objects.
      (exposition-only member object*)

      [edit]Member functions

      constructs acartesian_product_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

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

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_ranges_cartesian_product202207L(C++23)std::ranges::cartesian_product_view

      [edit]Example

      Run this code
      #include <array>#include <iostream>#include <list>#include <ranges>#include <string>#include <vector> void print(std::tuple<charconst&,intconst&,std::stringconst&> t,int pos){constauto&[a, b, c]= t;std::cout<<'('<< a<<' '<< b<<' '<< c<<')'<<(pos%4?" ":"\n");} int main(){constauto x=std::array{'A','B'};constauto y=std::vector{1,2,3};constauto z=std::list<std::string>{"α","β","γ","δ"}; for(int i{1};autoconst& tuple: std::views::cartesian_product(x, y, z))        print(tuple, i++);}

      Output:

      (A 1 α) (A 1 β) (A 1 γ) (A 1 δ)(A 2 α) (A 2 β) (A 2 γ) (A 2 δ)(A 3 α) (A 3 β) (A 3 γ) (A 3 δ)(B 1 α) (B 1 β) (B 1 γ) (B 1 δ)(B 2 α) (B 2 β) (B 2 γ) (B 2 δ)(B 3 α) (B 3 β) (B 3 γ) (B 3 δ)

      [edit]References

      • C++23 standard (ISO/IEC 14882:2024):
      • 26.7.31 Cartesian product view [range.stride]

      [edit]See also

      aview consisting of tuples of references to corresponding elements of the adapted views
      (class template)(customization point object)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/cartesian_product_view&oldid=177003"

      [8]ページ先頭

      ©2009-2025 Movatter.jp