|
| 1 | +/** TRACCC library, part of the ACTS project (R&D line) |
| 2 | + * |
| 3 | + * (c) 2025 CERN for the benefit of the ACTS project |
| 4 | + * |
| 5 | + * Mozilla Public License Version 2.0 |
| 6 | + */ |
| 7 | + |
| 8 | +#pragma once |
| 9 | + |
| 10 | +#include <type_traits> |
| 11 | +#include <utility> |
| 12 | + |
| 13 | +#include "traccc/definitions/qualifiers.hpp" |
| 14 | + |
| 15 | +namespace traccc { |
| 16 | + |
| 17 | +template <typename... Ts> |
| 18 | +struct tuple {}; |
| 19 | + |
| 20 | +template <typename T, typename... Ts> |
| 21 | +struct tuple<T, Ts...> { |
| 22 | + |
| 23 | + TRACCC_HOST_DEVICE constexpr tuple(){}; |
| 24 | + |
| 25 | + constexpr tuple(const tuple &o) requires( |
| 26 | + std::is_copy_constructible_v<T> && |
| 27 | + (std::is_copy_constructible_v<Ts> && ...)) = default; |
| 28 | + |
| 29 | + template <typename U, typename... Us> |
| 30 | + requires std::is_constructible_v<T, U &&> |
| 31 | + &&std::is_constructible_v<tuple<Ts...>, Us &&...> |
| 32 | + TRACCC_HOST_DEVICE explicit constexpr tuple( |
| 33 | + const tuple<U, Us...> &o) |
| 34 | + : v(o.v), r(o.r) {} |
| 35 | + |
| 36 | + constexpr tuple(tuple &&o) noexcept |
| 37 | + requires(std::is_move_constructible_v<T> && |
| 38 | + (std::is_move_constructible_v<Ts> && ...)) = default; |
| 39 | + |
| 40 | + template <typename U, typename... Us> |
| 41 | + requires std::is_constructible_v<T, U &&> |
| 42 | + &&std::is_constructible_v<tuple<Ts...>, Us &&...> |
| 43 | + TRACCC_HOST_DEVICE explicit constexpr tuple(tuple<U, Us...> &&o) |
| 44 | + : v(std::move(o.v)), r(std::move(o.r)) {} |
| 45 | + |
| 46 | + template <typename U, typename... Us> |
| 47 | + requires std::is_constructible_v<T, U &&> |
| 48 | + &&std::is_constructible_v<tuple<Ts...>, Us &&...> && |
| 49 | + (!(std::is_same_v<tuple, U> || |
| 50 | + (std::is_same_v<tuple, Us> || ...))) TRACCC_HOST_DEVICE |
| 51 | + explicit constexpr tuple(U &&_v, Us &&... _r) |
| 52 | + : v(std::forward<U>(_v)), |
| 53 | + r(std::forward<Us>(_r)...) {} |
| 54 | + |
| 55 | + constexpr ~tuple() noexcept = default; |
| 56 | + |
| 57 | + constexpr tuple &operator=(const tuple &other) requires( |
| 58 | + std::is_copy_assignable_v<T> && |
| 59 | + (std::is_copy_assignable_v<Ts> && ...)) = default; |
| 60 | + |
| 61 | + template <typename U, typename... Us> |
| 62 | + TRACCC_HOST_DEVICE constexpr tuple & |
| 63 | + operator=(const tuple<U, Us...> &other) requires( |
| 64 | + std::is_assignable_v<T &, const U &> && |
| 65 | + (std::is_assignable_v<Ts &, const Us &> && ...)) { |
| 66 | + v = other.v; |
| 67 | + r = other.r; |
| 68 | + return *this; |
| 69 | + } |
| 70 | + |
| 71 | + constexpr tuple &operator=(tuple &&other) noexcept |
| 72 | + requires(std::is_move_assignable_v<T> && |
| 73 | + (std::is_move_assignable_v<Ts> && ...)) = default; |
| 74 | + |
| 75 | + template <typename U, typename... Us> |
| 76 | + TRACCC_HOST_DEVICE constexpr tuple &operator=( |
| 77 | + tuple<U, Us...> &&other) requires(std::is_assignable_v<T &, U> && |
| 78 | + (std::is_assignable_v<Ts &, Us> && |
| 79 | + ...)) { |
| 80 | + v = std::move(other.v); |
| 81 | + r = std::move(other.r); |
| 82 | + return *this; |
| 83 | + } |
| 84 | + |
| 85 | + T v; |
| 86 | + tuple<Ts...> r; |
| 87 | +}; |
| 88 | +} // namespace traccc |
0 commit comments