46 template <std::
size_t Idx>
48 KOKKOS_INLINE_FUNCTION
auto&
get() noexcept {
49 if constexpr (Idx == i) {
52 return next.template get<Idx>();
55 template <std::
size_t Idx>
57 KOKKOS_INLINE_FUNCTION
const auto&
get() const noexcept {
58 if constexpr (Idx == i) {
61 return next.template get<Idx>();
64 TupleImpl& operator=(
const TupleImpl<i, N, T, R, Ts...>& t)
65 requires(std::is_copy_assignable_v<T> && std::is_copy_assignable_v<R>
66 && (std::is_copy_assignable_v<Ts> && ...))
68 TupleImpl& operator=(TupleImpl<i, N, T, R, Ts...>&& t)
69 requires(std::is_move_assignable_v<T> && std::is_move_assignable_v<R>
70 && (std::is_move_assignable_v<Ts> && ...))
72 TupleImpl(
const TupleImpl<i, N, T, R, Ts...>& t)
73 requires(std::is_copy_constructible_v<T> && std::is_copy_constructible_v<R>
74 && (std::is_copy_constructible_v<Ts> && ...))
76 TupleImpl(TupleImpl<i, N, T, R, Ts...>&& t)
77 requires(std::is_move_constructible_v<T> && std::is_move_constructible_v<R>
78 && (std::is_move_constructible_v<Ts> && ...))
82 requires(std::is_default_constructible_v<T> && std::is_default_constructible_v<R>
83 && (std::is_default_constructible_v<Ts> && ...))
85 template <
typename CtorT,
typename CtorR,
typename... CtorTs>
86 KOKKOS_INLINE_FUNCTION TupleImpl(CtorT&& t, CtorR&& r, CtorTs&&... ts)
87 : val(std::forward<T>(t))
88 , next(std::forward<CtorR>(r), std::forward<CtorTs>(ts)...) {}
126 TupleImpl<0,
sizeof...(Ts), Ts...> tupleImpl_m;
129 constexpr static std::size_t dim =
sizeof...(Ts);
130 constexpr static std::size_t size =
sizeof...(Ts);
131 template <std::
size_t Idx>
132 requires(Idx <
sizeof...(Ts))
133 KOKKOS_INLINE_FUNCTION
auto&& get()
noexcept {
134 return tupleImpl_m.template get<Idx>();
136 template <std::
size_t Idx>
137 requires(Idx <
sizeof...(Ts))
138 KOKKOS_INLINE_FUNCTION
auto&& get()
const noexcept {
139 return tupleImpl_m.template get<Idx>();
141 template <
typename Functor, std::size_t Idx,
typename... OtherTs>
142 KOKKOS_INLINE_FUNCTION
int applySingle(Functor func,
const Tuple<OtherTs...>& other)
143 requires(std::is_copy_assignable_v<Ts> && ...)
145 func(get<Idx>(), other.template get<Idx>());
148 template <
typename Functor,
typename... OtherTs, std::size_t... Idx>
149 KOKKOS_INLINE_FUNCTION
void applySequence(Functor func,
const Tuple<OtherTs...>& other,
150 const std::index_sequence<Idx...>&) {
151 int val = (applySingle<Functor, Idx, OtherTs...>(func, other) ^ ...);
154 template <std::size_t Idx,
typename... OtherTs>
156 requires(std::is_copy_assignable_v<Ts> && ...)
158 (get<Idx>() = other.template get<Idx>());
161 template <
typename... OtherTs, std::size_t... Idx>
163 const std::index_sequence<Idx...>&)
164 requires(std::is_copy_assignable_v<Ts> && ...)
166 int val = (assignToSingle<Idx, OtherTs...>(other) ^ ...);
169 template <std::size_t Idx,
typename... OtherTs>
171 requires(std::is_move_assignable_v<Ts> && ...)
173 (get<Idx>() = std::move(other.template get<Idx>()));
176 template <
typename... OtherTs, std::size_t... Idx>
178 const std::index_sequence<Idx...>&)
179 requires(std::is_move_assignable_v<Ts> && ...)
181 int val = (assignToSingle<Idx, OtherTs...>(std::move(other)) ^ ...);
184 template <
typename... OtherTs>
186 requires(std::is_copy_assignable_v<Ts> && ...)
188 assignToSequence(other, std::make_index_sequence<
sizeof...(Ts)>{});
192 template <
typename... OtherTs>
194 requires(std::is_move_assignable_v<Ts> && ...)
196 assignToSequence(std::move(other), std::make_index_sequence<
sizeof...(Ts)>{});
199 KOKKOS_INLINE_FUNCTION
Tuple& operator+=(
const Tuple& other)
200 requires(std::is_arithmetic_v<Ts> && ...)
203 KOKKOS_LAMBDA(
auto& x,
const auto& y) { x += y; }, other,
204 std::make_index_sequence<
sizeof...(Ts)>{});
207 KOKKOS_INLINE_FUNCTION
Tuple& operator-=(
const Tuple& other)
208 requires(std::is_arithmetic_v<Ts> && ...)
211 KOKKOS_LAMBDA(
auto& x,
const auto& y) { x -= y; }, other,
212 std::make_index_sequence<
sizeof...(Ts)>{});
215 KOKKOS_INLINE_FUNCTION
Tuple& operator*=(
const Tuple& other)
216 requires(std::is_arithmetic_v<Ts> && ...)
219 KOKKOS_LAMBDA(
auto& x,
const auto& y) { x *= y; }, other,
220 std::make_index_sequence<
sizeof...(Ts)>{});
223 KOKKOS_INLINE_FUNCTION
Tuple& operator/=(
const Tuple& other)
224 requires(std::is_arithmetic_v<Ts> && ...)
227 KOKKOS_LAMBDA(
auto& x,
const auto& y) { x /= y; }, other,
228 std::make_index_sequence<
sizeof...(Ts)>{});
231 KOKKOS_INLINE_FUNCTION
Tuple operator+(
const Tuple& other)
const
232 requires(std::is_arithmetic_v<Ts> && ...)
236 KOKKOS_INLINE_FUNCTION
Tuple operator-(
const Tuple& other)
const
237 requires(std::is_arithmetic_v<Ts> && ...)
241 KOKKOS_INLINE_FUNCTION
Tuple operator*(
const Tuple& other)
const
242 requires(std::is_arithmetic_v<Ts> && ...)
246 KOKKOS_INLINE_FUNCTION
Tuple operator/(
const Tuple& other)
const
247 requires(std::is_arithmetic_v<Ts> && ...)
251 template <std::size_t Idx, std::size_t N,
typename... OtherTs>
252 KOKKOS_INLINE_FUNCTION
bool lexicographicalLess(
const Tuple& other)
const {
253 if constexpr (Idx == N) {
256 return (get<Idx>() < other.template get<Idx>())
258 : lexicographicalLess<Idx + 1, N, OtherTs...>(other);
261 template <std::size_t Idx, std::size_t N,
typename... OtherTs>
262 KOKKOS_INLINE_FUNCTION
bool lexicographicalEquals(
const Tuple& other)
const {
263 if constexpr (Idx == N) {
266 return (get<Idx>() == other.template get<Idx>())
267 && lexicographicalEquals<Idx + 1, N, OtherTs...>(other);
270 template <
typename... OtherTs>
272 requires((
sizeof...(Ts) ==
sizeof...(OtherTs)) && (std::totally_ordered<Ts> && ...))
274 return lexicographicalLess<0,
sizeof...(Ts), OtherTs...>(other);
276 template <
typename... OtherTs>
278 requires((
sizeof...(Ts) ==
sizeof...(OtherTs)) && (std::totally_ordered<Ts> && ...))
280 return lexicographicalEquals<0,
sizeof...(Ts)>(other);
283 requires(std::is_copy_assignable_v<Ts> && ...)
287 requires(std::is_move_assignable_v<Ts> && ...)
291 requires(std::is_copy_constructible_v<Ts> && ...)
294 requires(std::is_move_constructible_v<Ts> && ...)
298 requires(std::is_default_constructible_v<Ts> && ...)
300 template <
typename... CtorTs>
301 requires(std::constructible_from<Ts, CtorTs> && ...)
302 KOKKOS_INLINE_FUNCTION
Tuple(CtorTs&&... args)
303 : tupleImpl_m(std::forward<Ts>(args)...) {}