Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
variadic tuple_of_iterator_references, zip_iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcorrigan authored and alliepiper committed Nov 5, 2020
1 parent 53034b4 commit 31ab48f
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 257 deletions.
192 changes: 38 additions & 154 deletions thrust/iterator/detail/tuple_of_iterator_references.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ namespace detail


template<
typename T0, typename T1, typename T2,
typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8,
typename T9
typename... Ts
>
class tuple_of_iterator_references
: public thrust::tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>
: public thrust::tuple<Ts...>
{
private:
typedef thrust::tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9> super_t;
typedef thrust::tuple<Ts...> super_t;

public:
// allow implicit construction from tuple<refs>
Expand All @@ -49,9 +46,9 @@ template<
// allow assignment from tuples
// XXX might be worthwhile to guard this with an enable_if is_assignable
__thrust_exec_check_disable__
template<typename U1, typename U2>
template<typename... Us>
inline __host__ __device__
tuple_of_iterator_references &operator=(const detail::cons<U1,U2> &other)
tuple_of_iterator_references &operator=(const thrust::tuple<Us...> &other)
{
super_t::operator=(other);
return *this;
Expand All @@ -72,24 +69,21 @@ template<
// XXX perhaps we should generalize to reference<T>
// we could captures reference<pair> this way
__thrust_exec_check_disable__
template<typename U0, typename U1, typename U2,
typename U3, typename U4, typename U5,
typename U6, typename U7, typename U8,
typename U9,
typename Pointer, typename Derived>
template<typename Pointer, typename Derived,
typename... Us>
inline __host__ __device__
// XXX gcc-4.2 crashes on is_assignable
// typename thrust::detail::enable_if<
// thrust::detail::is_assignable<
// super_t,
// const thrust::tuple<U0,U1,U2,U3,U4,U5,U6,U7,U8,U9>
// const thrust::tuple<Us...>
// >::value,
// tuple_of_iterator_references &
// >::type
tuple_of_iterator_references &
operator=(const thrust::reference<thrust::tuple<U0,U1,U2,U3,U4,U5,U6,U7,U8,U9>, Pointer, Derived> &other)
operator=(const thrust::reference<thrust::tuple<Us...>, Pointer, Derived> &other)
{
typedef thrust::tuple<U0,U1,U2,U3,U4,U5,U6,U7,U8,U9> tuple_type;
typedef thrust::tuple<Us...> tuple_type;

// XXX perhaps this could be accelerated
tuple_type other_tuple = other;
Expand All @@ -102,144 +96,9 @@ template<
inline __host__ __device__
tuple_of_iterator_references() {}

inline __host__ __device__
tuple_of_iterator_references(typename access_traits<T0>::parameter_type t0)
: super_t(t0,
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()))
{}

inline __host__ __device__
tuple_of_iterator_references(typename access_traits<T0>::parameter_type t0,
typename access_traits<T1>::parameter_type t1)
: super_t(t0, t1,
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()))
{}

inline __host__ __device__
tuple_of_iterator_references(typename access_traits<T0>::parameter_type t0,
typename access_traits<T1>::parameter_type t1,
typename access_traits<T2>::parameter_type t2)
: super_t(t0, t1, t2,
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()))
{}

inline __host__ __device__
tuple_of_iterator_references(typename access_traits<T0>::parameter_type t0,
typename access_traits<T1>::parameter_type t1,
typename access_traits<T2>::parameter_type t2,
typename access_traits<T3>::parameter_type t3)
: super_t(t0, t1, t2, t3,
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()))
{}

inline __host__ __device__
tuple_of_iterator_references(typename access_traits<T0>::parameter_type t0,
typename access_traits<T1>::parameter_type t1,
typename access_traits<T2>::parameter_type t2,
typename access_traits<T3>::parameter_type t3,
typename access_traits<T4>::parameter_type t4)
: super_t(t0, t1, t2, t3, t4,
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()))
{}

inline __host__ __device__
tuple_of_iterator_references(typename access_traits<T0>::parameter_type t0,
typename access_traits<T1>::parameter_type t1,
typename access_traits<T2>::parameter_type t2,
typename access_traits<T3>::parameter_type t3,
typename access_traits<T4>::parameter_type t4,
typename access_traits<T5>::parameter_type t5)
: super_t(t0, t1, t2, t3, t4, t5,
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()))
{}

inline __host__ __device__
tuple_of_iterator_references(typename access_traits<T0>::parameter_type t0,
typename access_traits<T1>::parameter_type t1,
typename access_traits<T2>::parameter_type t2,
typename access_traits<T3>::parameter_type t3,
typename access_traits<T4>::parameter_type t4,
typename access_traits<T5>::parameter_type t5,
typename access_traits<T6>::parameter_type t6)
: super_t(t0, t1, t2, t3, t4, t5, t6,
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()))
{}

inline __host__ __device__
tuple_of_iterator_references(typename access_traits<T0>::parameter_type t0,
typename access_traits<T1>::parameter_type t1,
typename access_traits<T2>::parameter_type t2,
typename access_traits<T3>::parameter_type t3,
typename access_traits<T4>::parameter_type t4,
typename access_traits<T5>::parameter_type t5,
typename access_traits<T6>::parameter_type t6,
typename access_traits<T7>::parameter_type t7)
: super_t(t0, t1, t2, t3, t4, t5, t6, t7,
static_cast<const null_type&>(null_type()),
static_cast<const null_type&>(null_type()))
{}

inline __host__ __device__
tuple_of_iterator_references(typename access_traits<T0>::parameter_type t0,
typename access_traits<T1>::parameter_type t1,
typename access_traits<T2>::parameter_type t2,
typename access_traits<T3>::parameter_type t3,
typename access_traits<T4>::parameter_type t4,
typename access_traits<T5>::parameter_type t5,
typename access_traits<T6>::parameter_type t6,
typename access_traits<T7>::parameter_type t7,
typename access_traits<T8>::parameter_type t8)
: super_t(t0, t1, t2, t3, t4, t5, t6, t7, t8,
static_cast<const null_type&>(null_type()))
{}

inline __host__ __device__
tuple_of_iterator_references(typename access_traits<T0>::parameter_type t0,
typename access_traits<T1>::parameter_type t1,
typename access_traits<T2>::parameter_type t2,
typename access_traits<T3>::parameter_type t3,
typename access_traits<T4>::parameter_type t4,
typename access_traits<T5>::parameter_type t5,
typename access_traits<T6>::parameter_type t6,
typename access_traits<T7>::parameter_type t7,
typename access_traits<T8>::parameter_type t8,
typename access_traits<T9>::parameter_type t9)
: super_t(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)
inline __host__ __device__
tuple_of_iterator_references(typename access_traits<Ts>::parameter_type... ts)
: super_t(ts...)
{}
};

Expand All @@ -259,5 +118,30 @@ void swap(tuple_of_iterator_references<Ts...> x,


} // end detail

// define tuple_size, tuple_element, etc.
template<class... Ts>
struct tuple_size<detail::tuple_of_iterator_references<Ts...>>
: std::integral_constant<size_t, sizeof...(Ts)>
{};

template<size_t i>
struct tuple_element<i, detail::tuple_of_iterator_references<>> {};


template<class T, class... Ts>
struct tuple_element<0, detail::tuple_of_iterator_references<T,Ts...>>
{
using type = T;
};


template<size_t i, class T, class... Ts>
struct tuple_element<i, detail::tuple_of_iterator_references<T,Ts...>>
{
using type = typename tuple_element<i - 1, detail::tuple_of_iterator_references<Ts...>>::type;
};


} // end thrust

Loading

0 comments on commit 31ab48f

Please sign in to comment.