Skip to content

Commit 3e2f11b

Browse files
committed
Add traccc tuple and pair types
This commit replaces the Thrust tuple and pair types from the traccc core library, as this dependency on Thrust is causing a lot of build headaches. Since we use the Thrust dependencies very sparsely in core, it is easier to remove them than to try to work around them.
1 parent 8db2c76 commit 3e2f11b

File tree

4 files changed

+112
-8
lines changed

4 files changed

+112
-8
lines changed

core/include/traccc/edm/details/container_base.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
// Project include(s).
1111
#include "traccc/definitions/qualifiers.hpp"
1212
#include "traccc/edm/details/container_element.hpp"
13+
#include "traccc/utils/pair.hpp"
1314

1415
// VecMem include(s).
1516
#include <vecmem/memory/memory_resource.hpp>
1617

17-
// Thrust include(s).
18-
#include <thrust/pair.h>
19-
2018
// System include(s).
2119
#include <cassert>
2220
#include <stdexcept>
@@ -38,7 +36,7 @@ namespace traccc {
3836
template <typename header_t, typename item_t,
3937
template <typename> class vector_t,
4038
template <typename> class jagged_vector_t,
41-
template <typename, typename> class pair_t = thrust::pair>
39+
template <typename, typename> class pair_t = traccc::pair>
4240
class container_base {
4341
public:
4442
/// @name Type definitions

core/include/traccc/finding/candidate_link.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
// Project include(s).
1111
#include "traccc/edm/measurement.hpp"
12-
13-
// Thrust include(s).
14-
#include <thrust/pair.h>
12+
#include "traccc/utils/pair.hpp"
1513

1614
namespace traccc {
1715

@@ -20,7 +18,7 @@ namespace traccc {
2018
struct candidate_link {
2119

2220
// Type of index
23-
using link_index_type = thrust::pair<unsigned int, unsigned int>;
21+
using link_index_type = traccc::pair<unsigned int, unsigned int>;
2422

2523
// Index of link from the previous step
2624
link_index_type previous;

core/include/traccc/utils/pair.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
namespace traccc {
11+
template <typename T1, typename T2>
12+
struct pair {
13+
public:
14+
using first_type = T1;
15+
using second_type = T2;
16+
17+
T1 first;
18+
T2 second;
19+
};
20+
} // namespace traccc
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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

Comments
 (0)