10#ifndef EIGEN_TUPLE_GPU
11#define EIGEN_TUPLE_GPU
23template <
size_t N,
typename... Types>
27template <
size_t N,
typename T1,
typename... Ts>
28class TupleImpl<N, T1, Ts...> {
31 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
34 template <
typename U1 = T1,
35 typename EnableIf = std::enable_if_t<std::is_default_constructible<U1>::value &&
36 reduce_all<std::is_default_constructible<Ts>::value...>::value>>
37 EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC TupleImpl() : head_{}, tail_{} {}
40 template <
typename U1,
typename... Us,
42 typename EnableIf = std::enable_if_t<
44 sizeof...(Us) ==
sizeof...(Ts) && (
46 N > 1 || std::is_convertible<U1, T1>::value)>>
47 EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC TupleImpl(U1&& arg1, Us&&... args)
48 : head_(std::forward<U1>(arg1)), tail_(std::forward<Us>(args)...) {}
51 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T1& head() {
return head_; }
53 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
const T1& head()
const {
return head_; }
56 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TupleImpl<N - 1, Ts...>& tail() {
return tail_; }
58 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
const TupleImpl<N - 1, Ts...>& tail()
const {
return tail_; }
60 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void swap(TupleImpl& other) {
62 swap(head_, other.head_);
63 swap(tail_, other.tail_);
66 template <
typename... UTypes>
67 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TupleImpl& operator=(
const TupleImpl<N, UTypes...>& other) {
73 template <
typename... UTypes>
74 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TupleImpl& operator=(TupleImpl<N, UTypes...>&& other) {
75 head_ = std::move(other.head_);
76 tail_ = std::move(other.tail_);
82 template <
size_t M,
typename... UTypes>
83 friend class TupleImpl;
86 TupleImpl<N - 1, Ts...> tail_;
91class TupleImpl<size_t(0)> {};
93template <
typename TupleType>
94struct is_tuple : std::false_type {};
96template <
typename... Types>
97struct is_tuple<TupleImpl<sizeof...(Types), Types...>> : std::true_type {};
100template <
size_t Idx,
typename T1,
typename... Ts>
101struct tuple_get_impl {
102 using TupleType = TupleImpl<
sizeof...(Ts) + 1, T1, Ts...>;
103 using ReturnType =
typename tuple_get_impl<Idx - 1, Ts...>::ReturnType;
105 static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE ReturnType& run(TupleType& tuple) {
106 return tuple_get_impl<Idx - 1, Ts...>::run(tuple.tail());
109 static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
const ReturnType& run(
const TupleType& tuple) {
110 return tuple_get_impl<Idx - 1, Ts...>::run(tuple.tail());
115template <
typename T1,
typename... Ts>
116struct tuple_get_impl<0, T1, Ts...> {
117 using TupleType = TupleImpl<
sizeof...(Ts) + 1, T1, Ts...>;
118 using ReturnType = T1;
120 static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T1& run(TupleType& tuple) {
return tuple.head(); }
122 static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
const T1& run(
const TupleType& tuple) {
128template <
size_t NTuples,
typename... Tuples>
129struct tuple_cat_impl;
131template <
size_t NTuples,
size_t N1,
typename... Args1,
size_t N2,
typename... Args2,
typename... Tuples>
132struct tuple_cat_impl<NTuples, TupleImpl<N1, Args1...>, TupleImpl<N2, Args2...>, Tuples...> {
133 using TupleType1 = TupleImpl<N1, Args1...>;
134 using TupleType2 = TupleImpl<N2, Args2...>;
135 using MergedTupleType = TupleImpl<N1 + N2, Args1..., Args2...>;
137 using ReturnType =
typename tuple_cat_impl<NTuples - 1, MergedTupleType, Tuples...>::ReturnType;
141 template <
typename Tuple1,
size_t... I1s,
typename Tuple2,
size_t... I2s,
typename... MoreTuples>
142 static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ReturnType run(Tuple1&& tuple1,
143 std::index_sequence<I1s...>,
145 std::index_sequence<I2s...>,
146 MoreTuples&&... tuples) {
147 return tuple_cat_impl<NTuples - 1, MergedTupleType, Tuples...>::run(
148 MergedTupleType(tuple_get_impl<I1s, Args1...>::run(std::forward<Tuple1>(tuple1))...,
149 tuple_get_impl<I2s, Args2...>::run(std::forward<Tuple2>(tuple2))...),
150 std::forward<MoreTuples>(tuples)...);
154 template <
typename Tuple1,
typename Tuple2,
typename... MoreTuples>
155 static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ReturnType run(Tuple1&& tuple1, Tuple2&& tuple2,
156 MoreTuples&&... tuples) {
157 return run(std::forward<Tuple1>(tuple1), std::make_index_sequence<N1>{}, std::forward<Tuple2>(tuple2),
158 std::make_index_sequence<N2>{}, std::forward<MoreTuples>(tuples)...);
163template <
size_t N,
typename... Args>
164struct tuple_cat_impl<1, TupleImpl<N, Args...>> {
165 using ReturnType = TupleImpl<N, Args...>;
167 template <
typename Tuple1>
168 static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ReturnType run(Tuple1&& tuple1) {
175struct tuple_cat_impl<0> {
176 using ReturnType = TupleImpl<0>;
177 static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ReturnType run() {
return ReturnType{}; }
182struct unwrap_reference_wrapper {
187struct unwrap_reference_wrapper<std::reference_wrapper<T>> {
194 using type =
typename unwrap_reference_wrapper<typename std::decay<T>::type>::type;
200template <
typename Tuple>
203template <
typename... Types>
204struct tuple_size<TupleImpl<sizeof...(Types), Types...>> : std::integral_constant<size_t, sizeof...(Types)> {};
213template <
size_t Idx,
typename... Types>
214EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const typename tuple_get_impl<Idx, Types...>::ReturnType& get(
215 const TupleImpl<
sizeof...(Types), Types...>& tuple) {
216 return tuple_get_impl<Idx, Types...>::run(tuple);
219template <
size_t Idx,
typename... Types>
220EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
typename tuple_get_impl<Idx, Types...>::ReturnType& get(
221 TupleImpl<
sizeof...(Types), Types...>& tuple) {
222 return tuple_get_impl<Idx, Types...>::run(tuple);
230template <
typename... Tuples,
typename EnableIf = std::enable_if_t<
231 internal::reduce_all<is_tuple<typename std::decay<Tuples>::type>::value...>::value>>
232EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
233 typename tuple_cat_impl<
sizeof...(Tuples),
typename std::decay<Tuples>::type...>::ReturnType
234 tuple_cat(Tuples&&... tuples) {
235 return tuple_cat_impl<
sizeof...(Tuples),
typename std::decay<Tuples>::type...>::run(std::forward<Tuples>(tuples)...);
241template <
typename... Args,
typename ReturnType = TupleImpl<
sizeof...(Args), Args&...>>
242EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ReturnType tie(Args&... args) EIGEN_NOEXCEPT {
243 return ReturnType{args...};
249template <
typename... Args,
typename ReturnType = TupleImpl<
sizeof...(Args),
typename unwrap_decay<Args>::type...>>
250EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ReturnType make_tuple(Args&&... args) {
251 return ReturnType{std::forward<Args>(args)...};
257template <
typename... Args>
258EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TupleImpl<
sizeof...(Args), Args...> forward_as_tuple(
260 return TupleImpl<
sizeof...(Args), Args...>(std::forward<Args>(args)...);
266template <
typename... Types>
267using tuple = TupleImpl<
sizeof...(Types), Types...>;
Namespace containing all symbols from the Eigen library.
Definition Core:137