From 00fff4b96fbfd3efd68516acd6c4e28df666aacc Mon Sep 17 00:00:00 2001 From: Andrew Corrigan Date: Mon, 12 Oct 2020 09:16:19 -0400 Subject: [PATCH 1/8] Prepares raw_reference_cast for variadic tuple --- thrust/detail/raw_reference_cast.h | 125 +++++++---------------------- 1 file changed, 30 insertions(+), 95 deletions(-) diff --git a/thrust/detail/raw_reference_cast.h b/thrust/detail/raw_reference_cast.h index a678144e2..aea317c52 100644 --- a/thrust/detail/raw_reference_cast.h +++ b/thrust/detail/raw_reference_cast.h @@ -48,26 +48,12 @@ template // specialize is_unwrappable // a tuple is_unwrappable if any of its elements is_unwrappable -template< - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 -> +template struct is_unwrappable< - thrust::tuple + thrust::tuple > : or_< - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable + is_unwrappable... > {}; @@ -75,25 +61,13 @@ template< // specialize is_unwrappable // a tuple_of_iterator_references is_unwrappable if any of its elements is_unwrappable template< - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 + typename... Ts > struct is_unwrappable< - thrust::detail::tuple_of_iterator_references + thrust::detail::tuple_of_iterator_references > : or_< - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable, - is_unwrappable + is_unwrappable... > {}; @@ -173,51 +147,27 @@ template // recurse on tuples template < - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 + typename... Ts > struct raw_reference_tuple_helper< - thrust::tuple + thrust::tuple > { typedef thrust::tuple< - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type + typename raw_reference_tuple_helper::type... > type; }; template < - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 + typename... Ts > struct raw_reference_tuple_helper< - thrust::detail::tuple_of_iterator_references + thrust::detail::tuple_of_iterator_references > { typedef thrust::detail::tuple_of_iterator_references< - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type, - typename raw_reference_tuple_helper::type + typename raw_reference_tuple_helper::type... > type; }; @@ -232,17 +182,14 @@ template < // then the raw_reference of tuple_type is a tuple of its members' raw_references // else the raw_reference of tuple_type is tuple_type & template < - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 + typename... Ts > struct raw_reference< - thrust::tuple + thrust::tuple > { private: - typedef thrust::tuple tuple_type; + typedef thrust::tuple tuple_type; public: typedef typename eval_if< @@ -254,17 +201,14 @@ template < template < - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 + typename... Ts > struct raw_reference< - thrust::detail::tuple_of_iterator_references + thrust::detail::tuple_of_iterator_references > { private: - typedef detail::tuple_of_iterator_references tuple_type; + typedef detail::tuple_of_iterator_references tuple_type; public: typedef typename raw_reference_detail::raw_reference_tuple_helper::type type; @@ -295,19 +239,16 @@ typename detail::raw_reference::type template< - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 + typename... Ts > __host__ __device__ typename detail::enable_if_unwrappable< - thrust::detail::tuple_of_iterator_references, + thrust::detail::tuple_of_iterator_references, typename detail::raw_reference< - thrust::detail::tuple_of_iterator_references + thrust::detail::tuple_of_iterator_references >::type >::type -raw_reference_cast(thrust::detail::tuple_of_iterator_references t); +raw_reference_cast(thrust::detail::tuple_of_iterator_references t); namespace detail @@ -331,18 +272,15 @@ struct raw_reference_caster } template< - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 + typename... Ts > __host__ __device__ typename detail::raw_reference< - thrust::detail::tuple_of_iterator_references + thrust::detail::tuple_of_iterator_references >::type - operator()(thrust::detail::tuple_of_iterator_references t, + operator()(thrust::detail::tuple_of_iterator_references t, typename enable_if< - is_unwrappable >::value + is_unwrappable >::value >::type * = 0) { return thrust::raw_reference_cast(t); @@ -372,19 +310,16 @@ typename detail::raw_reference::type template< - typename T0, typename T1, typename T2, - typename T3, typename T4, typename T5, - typename T6, typename T7, typename T8, - typename T9 + typename... Ts > __host__ __device__ typename detail::enable_if_unwrappable< - thrust::detail::tuple_of_iterator_references, + thrust::detail::tuple_of_iterator_references, typename detail::raw_reference< - thrust::detail::tuple_of_iterator_references + thrust::detail::tuple_of_iterator_references >::type >::type -raw_reference_cast(thrust::detail::tuple_of_iterator_references t) +raw_reference_cast(thrust::detail::tuple_of_iterator_references t) { thrust::detail::raw_reference_caster f; From a526da1150f3f693691e05b51ccf77b4c85912ce Mon Sep 17 00:00:00 2001 From: Andrew Corrigan Date: Mon, 12 Oct 2020 09:59:36 -0400 Subject: [PATCH 2/8] Prepares swap(tuple_of_iterator_references, tuple_of_iterator_references) for variadic tuple --- thrust/iterator/detail/tuple_of_iterator_references.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/thrust/iterator/detail/tuple_of_iterator_references.h b/thrust/iterator/detail/tuple_of_iterator_references.h index 93d7e05e4..8576c673d 100644 --- a/thrust/iterator/detail/tuple_of_iterator_references.h +++ b/thrust/iterator/detail/tuple_of_iterator_references.h @@ -247,12 +247,12 @@ template< // this overload of swap() permits swapping tuple_of_iterator_references returned as temporaries from // iterator dereferences template< - typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, - typename U0, typename U1, typename U2, typename U3, typename U4, typename U5, typename U6, typename U7, typename U8, typename U9 + typename... Ts, + typename... Us > inline __host__ __device__ -void swap(tuple_of_iterator_references x, - tuple_of_iterator_references y) +void swap(tuple_of_iterator_references x, + tuple_of_iterator_references y) { x.swap(y); } From 22023d34797e6c9295394d032aee5a759eef9933 Mon Sep 17 00:00:00 2001 From: Andrew Corrigan Date: Mon, 12 Oct 2020 10:03:03 -0400 Subject: [PATCH 3/8] Prepares is_tuple_of_iterator_references for variadic tuple --- thrust/detail/internal_functional.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/thrust/detail/internal_functional.h b/thrust/detail/internal_functional.h index 9ae6634b7..dba2f8f79 100644 --- a/thrust/detail/internal_functional.h +++ b/thrust/detail/internal_functional.h @@ -281,13 +281,10 @@ template template struct is_tuple_of_iterator_references : thrust::detail::false_type {}; -template +template struct is_tuple_of_iterator_references< thrust::detail::tuple_of_iterator_references< - T1,T2,T3,T4,T5,T6,T7,T8,T9,T10 + Ts... > > : thrust::detail::true_type From 3eba25f2ceee72b5c90913b92e5e1ff274935a3a Mon Sep 17 00:00:00 2001 From: Andrew Corrigan Date: Mon, 12 Oct 2020 10:56:32 -0400 Subject: [PATCH 4/8] variadic or_ and_ --- thrust/detail/type_traits.h | 40 ++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/thrust/detail/type_traits.h b/thrust/detail/type_traits.h index 9bfe60d31..c663cffb0 100644 --- a/thrust/detail/type_traits.h +++ b/thrust/detail/type_traits.h @@ -391,22 +391,44 @@ template // mpl stuff +template + struct or_; -template - struct or_ +template <> + struct or_<> : public integral_constant< bool, - Condition1::value || Condition2::value || Condition3::value || Condition4::value || Condition5::value || Condition6::value || Condition7::value || Condition8::value || Condition9::value || Condition10::value + false_type::value // identity for or_ > { }; // end or_ -template - struct and_ - : public integral_constant +template + struct or_ + : public integral_constant< + bool, + Condition::value || or_::value + > +{ +}; // end or_ + +template + struct and_; + +template<> + struct and_<> + : public integral_constant< + bool, + true_type::value // identity for and_ + > +{ +}; // end and_ + +template + struct and_ + : public integral_constant< + bool, + Condition::value && and_::value> { }; // end and_ From 53a1d25ea421e4a0cc5af6a5fe43f42ce5295b37 Mon Sep 17 00:00:00 2001 From: Andrew Corrigan Date: Mon, 12 Oct 2020 10:59:05 -0400 Subject: [PATCH 5/8] variadic tuple_meta_transform --- thrust/detail/tuple_meta_transform.h | 143 ++------------------------- 1 file changed, 6 insertions(+), 137 deletions(-) diff --git a/thrust/detail/tuple_meta_transform.h b/thrust/detail/tuple_meta_transform.h index 4aca1a91b..176834d30 100644 --- a/thrust/detail/tuple_meta_transform.h +++ b/thrust/detail/tuple_meta_transform.h @@ -17,6 +17,7 @@ #pragma once #include +#include namespace thrust { @@ -26,148 +27,16 @@ namespace detail template class UnaryMetaFunction, - unsigned int sz = thrust::tuple_size::value> + typename IndexSequence = thrust::make_index_sequence::value>> struct tuple_meta_transform; template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef null_type type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform -{ - typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type - > type; -}; - -template class UnaryMetaFunction> - struct tuple_meta_transform + template class UnaryMetaFunction, + size_t... Is> + struct tuple_meta_transform> { typedef thrust::tuple< - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type, - typename UnaryMetaFunction::type>::type + typename UnaryMetaFunction::type>::type... > type; }; From 22e6dd1a8514690fdb935b33b9042d2c56f005bc Mon Sep 17 00:00:00 2001 From: Andrew Corrigan Date: Mon, 12 Oct 2020 11:22:46 -0400 Subject: [PATCH 6/8] variadic tuple_transform --- thrust/detail/tuple_transform.h | 347 +------------------------------- 1 file changed, 6 insertions(+), 341 deletions(-) diff --git a/thrust/detail/tuple_transform.h b/thrust/detail/tuple_transform.h index 166fab3cb..1de2402b0 100644 --- a/thrust/detail/tuple_transform.h +++ b/thrust/detail/tuple_transform.h @@ -28,332 +28,15 @@ namespace detail template class UnaryMetaFunction, typename UnaryFunction, - unsigned int sz = thrust::tuple_size::value> + typename IndexSequence = thrust::make_index_sequence::value>> struct tuple_transform_functor; template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &, UnaryFunction) - { - return thrust::null_type(); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &, UnaryFunction) - { - return thrust::null_type(); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t)), - f(thrust::get<7>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t)), - f(thrust::get<7>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor -{ - static __host__ - typename tuple_meta_transform::type - do_it_on_the_host(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t)), - f(thrust::get<7>(t)), - f(thrust::get<8>(t))); - } - - static __host__ __device__ - typename tuple_meta_transform::type - do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f) - { - typedef typename tuple_meta_transform::type XfrmTuple; - - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t)), - f(thrust::get<7>(t)), - f(thrust::get<8>(t))); - } -}; - - -template class UnaryMetaFunction, - typename UnaryFunction> - struct tuple_transform_functor + typename UnaryFunction, + size_t... Is> + struct tuple_transform_functor> { static __host__ typename tuple_meta_transform::type @@ -361,16 +44,7 @@ template::type XfrmTuple; - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t)), - f(thrust::get<7>(t)), - f(thrust::get<8>(t)), - f(thrust::get<9>(t))); + return XfrmTuple(f(thrust::get(t))...); } static __host__ __device__ @@ -379,16 +53,7 @@ template::type XfrmTuple; - return XfrmTuple(f(thrust::get<0>(t)), - f(thrust::get<1>(t)), - f(thrust::get<2>(t)), - f(thrust::get<3>(t)), - f(thrust::get<4>(t)), - f(thrust::get<5>(t)), - f(thrust::get<6>(t)), - f(thrust::get<7>(t)), - f(thrust::get<8>(t)), - f(thrust::get<9>(t))); + return XfrmTuple(f(thrust::get(t))...); } }; From 6ff6c6d0b5301e3e55cdf77542bc3d3ef541fc09 Mon Sep 17 00:00:00 2001 From: Andrew Corrigan Date: Mon, 12 Oct 2020 12:19:46 -0400 Subject: [PATCH 7/8] variadic type_list --- testing/unittest/meta.h | 138 ++++++++-------------------------------- 1 file changed, 26 insertions(+), 112 deletions(-) diff --git a/testing/unittest/meta.h b/testing/unittest/meta.h index 39c62edb6..ed492634b 100644 --- a/testing/unittest/meta.h +++ b/testing/unittest/meta.h @@ -13,49 +13,10 @@ namespace unittest struct null_type {}; // this type encapsulates a list of -// up to 10 types -template +// types +template struct type_list { - typedef T0 type_0; - typedef T1 type_1; - typedef T2 type_2; - typedef T3 type_3; - typedef T4 type_4; - typedef T5 type_5; - typedef T6 type_6; - typedef T7 type_7; - typedef T8 type_8; - typedef T9 type_9; - typedef T10 type_10; - typedef T11 type_11; - typedef T12 type_12; - typedef T13 type_13; - typedef T14 type_14; - typedef T15 type_15; - typedef T16 type_16; - typedef T17 type_17; - typedef T18 type_18; - typedef T19 type_19; }; // this type provides a way of indexing @@ -66,26 +27,17 @@ template typedef null_type type; }; -template struct get_type { typedef typename List::type_0 type; }; -template struct get_type { typedef typename List::type_1 type; }; -template struct get_type { typedef typename List::type_2 type; }; -template struct get_type { typedef typename List::type_3 type; }; -template struct get_type { typedef typename List::type_4 type; }; -template struct get_type { typedef typename List::type_5 type; }; -template struct get_type { typedef typename List::type_6 type; }; -template struct get_type { typedef typename List::type_7 type; }; -template struct get_type { typedef typename List::type_8 type; }; -template struct get_type { typedef typename List::type_9 type; }; -template struct get_type { typedef typename List::type_10 type; }; -template struct get_type { typedef typename List::type_11 type; }; -template struct get_type { typedef typename List::type_12 type; }; -template struct get_type { typedef typename List::type_13 type; }; -template struct get_type { typedef typename List::type_14 type; }; -template struct get_type { typedef typename List::type_15 type; }; -template struct get_type { typedef typename List::type_16 type; }; -template struct get_type { typedef typename List::type_17 type; }; -template struct get_type { typedef typename List::type_18 type; }; -template struct get_type { typedef typename List::type_19 type; }; +template + struct get_type, 0> +{ + typedef T type; +}; + +template + struct get_type, i> +{ + typedef typename get_type, i - 1>::type type; +}; // this type and its specialization provides a way to // iterate over a type_list, and @@ -196,64 +148,26 @@ template