vecmem 1.18.0
Loading...
Searching...
No Matches
tuple.hpp
1/* VecMem project, part of the ACTS project (R&D line)
2 *
3 * (c) 2023-2025 CERN for the benefit of the ACTS project
4 *
5 * Mozilla Public License Version 2.0
6 */
7#pragma once
8
9// Local include(s).
10#include "vecmem/utils/type_traits.hpp"
11#include "vecmem/utils/types.hpp"
12
13// System include(s).
14#include <type_traits>
15
16namespace vecmem {
17
23template <typename... Ts>
24struct tuple {
25
26 // As long as we did everything correctly, this should only get instantiated
27 // with an empty parameter list, for the implementation to work correctly.
28 static_assert(sizeof...(Ts) == 0,
29 "There's a coding error in vecmem::tuple!");
30
32 constexpr tuple() = default;
33
34}; // struct tuple
35
49template <typename T, typename... Ts>
50struct tuple<T, Ts...> {
51
53 constexpr tuple() = default;
55 constexpr tuple(const tuple &) = default;
57 constexpr tuple(tuple &&) noexcept = default;
58
63 template <
65 std::enable_if_t<vecmem::details::conjunction_v<
66 std::is_constructible<T, std::decay_t<U>>,
67 std::is_constructible<Ts, std::decay_t<Us>>...>,
68 bool> = true>
69 VECMEM_HOST_AND_DEVICE constexpr explicit tuple(
70 const tuple<U, Us...> &parent)
71 : m_head(parent.m_head), m_tail(parent.m_tail) {}
72
78 template <
79 typename U, typename... Us,
80 std::enable_if_t<
81 vecmem::details::conjunction_v<
82 vecmem::details::negation<std::is_same<tuple<T, Ts...>, U>>,
83 std::is_constructible<T, U &&>,
84 std::is_constructible<Ts, Us &&>...>,
85 bool> = true>
86 VECMEM_HOST_AND_DEVICE constexpr tuple(U &&head, Us &&... tail)
87 : m_head(std::forward<U>(head)), m_tail(std::forward<Us>(tail)...) {}
88
97 template <typename U, typename... Us,
98 std::enable_if_t<vecmem::details::conjunction_v<
99 std::is_constructible<T, U &&>,
100 std::is_constructible<Ts, Us &&>...>,
101 bool> = true>
102 VECMEM_HOST_AND_DEVICE constexpr tuple(U &&head, tuple<Us...> &&tail)
103 : m_head(std::forward<U>(head)), m_tail(std::move(tail)) {}
104
106 constexpr tuple &operator=(const tuple &) = default;
109
115 std::enable_if_t<
116 vecmem::details::conjunction<
119 Us>...>::value,
120 bool> = true>
121 VECMEM_HOST_AND_DEVICE constexpr tuple &operator=(
122 const tuple<U, Us...> &parent) {
123 m_head = parent.m_head;
124 m_tail = parent.m_tail;
125 return *this;
126 }
127
132
133}; // struct tuple
134
137
145template <std::size_t I, typename... Ts>
146VECMEM_HOST_AND_DEVICE constexpr const auto &get(
147 const tuple<Ts...> &t) noexcept;
148
156template <std::size_t I, typename... Ts>
157VECMEM_HOST_AND_DEVICE constexpr auto &get(tuple<Ts...> &t) noexcept;
158
165template <typename... Ts>
166VECMEM_HOST_AND_DEVICE constexpr tuple<Ts &...> tie(Ts &... args);
167
174template <class... Ts>
175VECMEM_HOST_AND_DEVICE constexpr tuple<std::decay_t<Ts>...> make_tuple(
176 Ts &&... args);
177
183template <std::size_t I, class T>
185
191template <std::size_t I, typename... Ts>
192struct tuple_element<I, tuple<Ts...>> {
193
195 using type = std::decay_t<decltype(get<I>(std::declval<tuple<Ts...>>()))>;
196};
197
203template <std::size_t I, class T>
205
207
208} // namespace vecmem
209
210// Include the implementation.
211#include "vecmem/utils/impl/tuple.ipp"
An allocator class that wraps a memory resource.
Definition allocator.hpp:37
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
VECMEM_HOST_AND_DEVICE constexpr const auto & get(const tuple< Ts... > &t) noexcept
Get a constant element out of a tuple.
Definition tuple.ipp:58
VECMEM_HOST_AND_DEVICE constexpr tuple< std::decay_t< Ts >... > make_tuple(Ts &&... args)
Make a tuple with automatic type deduction.
Definition tuple.ipp:87
VECMEM_HOST_AND_DEVICE constexpr tuple< Ts &... > tie(Ts &... args)
Tie references to existing objects, into a tuple.
Definition tuple.ipp:81
typename tuple_element< I, T >::type tuple_element_t
Convenience accessor for the I-th element of a tuple.
Definition tuple.hpp:204
Implementation for std::negation.
Definition type_traits.hpp:91
constexpr tuple(tuple &&) noexcept=default
Default move constructor.
constexpr tuple & operator=(tuple &&) noexcept=default
Default move assignment operator.
T m_head
The first/head element of the tuple.
Definition tuple.hpp:129
VECMEM_HOST_AND_DEVICE constexpr tuple(U &&head, Us &&... tail)
Main constructor, from a list of tuple elements.
Definition tuple.hpp:86
constexpr tuple()=default
Default constructor.
VECMEM_HOST_AND_DEVICE constexpr tuple(U &&head, tuple< Us... > &&tail)
"Concatenation" constructor
Definition tuple.hpp:102
constexpr tuple(const tuple &)=default
Default copy constructor.
constexpr tuple & operator=(const tuple &)=default
Default copy assignment operator.
tuple< Ts... > m_tail
The rest of the tuple elements.
Definition tuple.hpp:131
std::decay_t< decltype(get< I >(std::declval< tuple< Ts... > >()))> type
Type of the I-th element of the specified tuple.
Definition tuple.hpp:195
Default/empty implementation for vecmem::tuple_element.
Definition tuple.hpp:184
Default tuple type.
Definition tuple.hpp:24
constexpr tuple()=default
Default constructor for the default tuple type.