10 #ifndef EIGEN_TUPLE_GPU
11 #define EIGEN_TUPLE_GPU
13 #include <type_traits>
20 namespace tuple_impl {
23 template<
size_t N,
typename... Types>
27 template<
size_t N,
typename T1,
typename... Ts>
28 class TupleImpl<N, T1, Ts...> {
34 template<
typename U1 = T1,
typename EnableIf = std::enable_if_t<
35 std::is_default_constructible<U1>::value
36 && reduce_all<std::is_default_constructible<Ts>::value...>::value
39 TupleImpl() : head_{}, tail_{} {}
42 template<
typename U1,
typename... Us,
44 typename EnableIf = std::enable_if_t<
46 sizeof...(Us) ==
sizeof...(Ts) && (
48 N > 1 || std::is_convertible<U1, T1>::value)
51 TupleImpl(U1&& arg1, Us&&... args)
52 : head_(std::forward<U1>(arg1)), tail_(std::forward<Us>(args)...) {}
61 const T1&
head()
const {
67 TupleImpl<N-1, Ts...>&
tail() {
72 const TupleImpl<N-1, Ts...>&
tail()
const {
77 void swap(TupleImpl& other) {
79 swap(head_, other.head_);
80 swap(tail_, other.tail_);
83 template<
typename... UTypes>
85 TupleImpl& operator=(
const TupleImpl<N, UTypes...>& other) {
91 template<
typename... UTypes>
93 TupleImpl& operator=(TupleImpl<N, UTypes...>&& other) {
94 head_ = std::move(other.head_);
95 tail_ = std::move(other.tail_);
101 template<
size_t M,
typename... UTypes>
102 friend class TupleImpl;
105 TupleImpl<N-1, Ts...> tail_;
110 class TupleImpl<size_t(0)> {};
112 template<
typename TupleType>
113 struct is_tuple : std::false_type {};
115 template<
typename... Types>
116 struct is_tuple< TupleImpl<sizeof...(Types), Types...> > : std::true_type {};
119 template<
size_t Idx,
typename T1,
typename... Ts>
120 struct tuple_get_impl {
121 using TupleType = TupleImpl<
sizeof...(Ts) + 1, T1, Ts...>;
122 using ReturnType =
typename tuple_get_impl<Idx - 1, Ts...>::ReturnType;
125 ReturnType& run(TupleType& tuple) {
126 return tuple_get_impl<Idx-1, Ts...>::run(tuple.tail());
130 const ReturnType& run(
const TupleType& tuple) {
131 return tuple_get_impl<Idx-1, Ts...>::run(tuple.tail());
136 template<
typename T1,
typename... Ts>
137 struct tuple_get_impl<0, T1, Ts...> {
138 using TupleType = TupleImpl<
sizeof...(Ts) + 1, T1, Ts...>;
139 using ReturnType = T1;
142 T1& run(TupleType& tuple) {
147 const T1& run(
const TupleType& tuple) {
153 template<
size_t NTuples,
typename... Tuples>
154 struct tuple_cat_impl;
156 template<
size_t NTuples,
size_t N1,
typename... Args1,
size_t N2,
typename... Args2,
typename... Tuples>
157 struct tuple_cat_impl<NTuples, TupleImpl<N1, Args1...>, TupleImpl<N2, Args2...>, Tuples...> {
158 using TupleType1 = TupleImpl<N1, Args1...>;
159 using TupleType2 = TupleImpl<N2, Args2...>;
160 using MergedTupleType = TupleImpl<N1 + N2, Args1..., Args2...>;
162 using ReturnType =
typename tuple_cat_impl<NTuples-1, MergedTupleType, Tuples...>::ReturnType;
166 template<
typename Tuple1,
size_t... I1s,
typename Tuple2,
size_t... I2s,
typename... MoreTuples>
168 ReturnType run(Tuple1&& tuple1, std::index_sequence<I1s...>,
169 Tuple2&& tuple2, std::index_sequence<I2s...>,
170 MoreTuples&&... tuples) {
171 return tuple_cat_impl<NTuples-1, MergedTupleType, Tuples...>::run(
172 MergedTupleType(tuple_get_impl<I1s, Args1...>::run(std::forward<Tuple1>(tuple1))...,
173 tuple_get_impl<I2s, Args2...>::run(std::forward<Tuple2>(tuple2))...),
174 std::forward<MoreTuples>(tuples)...);
178 template<
typename Tuple1,
typename Tuple2,
typename... MoreTuples>
180 ReturnType run(Tuple1&& tuple1, Tuple2&& tuple2, MoreTuples&&... tuples) {
181 return run(std::forward<Tuple1>(tuple1), std::make_index_sequence<N1>{},
182 std::forward<Tuple2>(tuple2), std::make_index_sequence<N2>{},
183 std::forward<MoreTuples>(tuples)...);
188 template<
size_t N,
typename... Args>
189 struct tuple_cat_impl<1, TupleImpl<N, Args...> > {
190 using ReturnType = TupleImpl<N, Args...>;
192 template<
typename Tuple1>
194 ReturnType run(Tuple1&& tuple1) {
201 struct tuple_cat_impl<0> {
202 using ReturnType = TupleImpl<0>;
204 ReturnType run() {
return ReturnType{}; }
208 template <
typename T>
209 struct unwrap_reference_wrapper {
using type =
T; };
211 template <
typename T>
212 struct unwrap_reference_wrapper<
std::reference_wrapper<T> > {
using type =
T&; };
215 template <
typename T>
216 struct unwrap_decay {
217 using type =
typename unwrap_reference_wrapper<typename std::decay<T>::type>::type;
223 template<
typename Tuple>
226 template<
typename... Types >
227 struct tuple_size< TupleImpl<sizeof...(Types), Types...> > : std::integral_constant<size_t, sizeof...(Types)> {};
236 template<
size_t Idx,
typename... Types>
238 const typename tuple_get_impl<Idx, Types...>::ReturnType&
239 get(
const TupleImpl<
sizeof...(Types), Types...>& tuple) {
240 return tuple_get_impl<Idx, Types...>::run(tuple);
243 template<
size_t Idx,
typename... Types>
245 typename tuple_get_impl<Idx, Types...>::ReturnType&
246 get(TupleImpl<
sizeof...(Types), Types...>& tuple) {
247 return tuple_get_impl<Idx, Types...>::run(tuple);
255 template<
typename... Tuples,
256 typename EnableIf = std::enable_if_t<
258 is_tuple<typename std::decay<Tuples>::type>::value...>::value>>
260 typename tuple_cat_impl<
sizeof...(Tuples),
typename std::decay<Tuples>::type...>::ReturnType
261 tuple_cat(Tuples&&... tuples) {
262 return tuple_cat_impl<
sizeof...(Tuples),
typename std::decay<Tuples>::type...>::run(std::forward<Tuples>(tuples)...);
268 template <
typename... Args,
typename ReturnType = TupleImpl<
sizeof...(Args), Args&...> >
271 return ReturnType{args...};
277 template <
typename... Args,
typename ReturnType = TupleImpl<
sizeof...(Args),
typename unwrap_decay<Args>::type...> >
279 ReturnType make_tuple(Args&&... args) {
280 return ReturnType{std::forward<Args>(args)...};
286 template <
typename... Args>
288 TupleImpl<
sizeof...(Args), Args...> forward_as_tuple(Args&&... args) {
289 return TupleImpl<
sizeof...(Args), Args...>(std::forward<Args>(args)...);
295 template<
typename... Types>
296 using tuple = TupleImpl<
sizeof...(Types), Types...>;
FixedSegmentReturnType<... >::Type head(NType n)
FixedSegmentReturnType<... >::Type tail(NType n)
#define EIGEN_ALWAYS_INLINE
#define EIGEN_DEVICE_FUNC
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Eigen::Triplet< double > T
std::is_same< std::integer_sequence< bool, values..., true >, std::integer_sequence< bool, true, values... > > reduce_all
void swap(scoped_array< T > &a, scoped_array< T > &b)