@@ -41,28 +41,32 @@ namespace type_traits
41
41
// /
42
42
// / @return A boolean that should be false for any type passed into this function.
43
43
// /
44
- template <typename T>
44
+ template <typename T>
45
45
constexpr inline autoware::common::types::bool8_t COMMON_PUBLIC impossible_branch () noexcept
46
46
{
47
47
return sizeof (T) == 0 ;
48
48
}
49
49
50
50
// / Find an index of a type in a tuple
51
- template <class QueryT , class TupleT >
51
+ template <class QueryT , class TupleT >
52
52
struct COMMON_PUBLIC index
53
53
{
54
54
static_assert (!std::is_same<TupleT, std::tuple<>>::value, " Could not find QueryT in given tuple" );
55
55
};
56
56
57
57
// / Specialization for a tuple that starts with the HeadT type. End of recursion.
58
- template <class HeadT , class ... Tail>
58
+ template <class HeadT , class ... Tail>
59
59
struct COMMON_PUBLIC index<HeadT, std::tuple<HeadT, Tail...>>
60
- : std::integral_constant<std::int32_t , 0 > {};
60
+ : std::integral_constant<std::int32_t , 0 >
61
+ {
62
+ };
61
63
62
64
// / Specialization for a tuple with a type different to QueryT that calls the recursive step.
63
- template <class QueryT , class HeadT , class ... Tail>
65
+ template <class QueryT , class HeadT , class ... Tail>
64
66
struct COMMON_PUBLIC index<QueryT, std::tuple<HeadT, Tail...>>
65
- : std::integral_constant<std::int32_t , 1 + index<QueryT, std::tuple<Tail...>>::value> {};
67
+ : std::integral_constant<std::int32_t , 1 + index<QueryT, std::tuple<Tail...>>::value>
68
+ {
69
+ };
66
70
67
71
// /
68
72
// / @brief Visit every element in a tuple.
@@ -75,13 +79,17 @@ struct COMMON_PUBLIC index<QueryT, std::tuple<HeadT, Tail...>>
75
79
// /
76
80
// / @return Does not return anything. Capture variables in a lambda to return any values.
77
81
// /
78
- template <std::size_t I = 0UL , typename Callable, typename ... TypesT>
79
- COMMON_PUBLIC inline constexpr typename std::enable_if_t <I == sizeof ...(TypesT)>
80
- visit (std::tuple<TypesT...> &, Callable) noexcept {}
82
+ template <std::size_t I = 0UL , typename Callable, typename ... TypesT>
83
+ COMMON_PUBLIC inline constexpr typename std::enable_if_t <I == sizeof ...(TypesT)> visit (
84
+ std::tuple<TypesT...> &, Callable) noexcept
85
+ {
86
+ }
81
87
// / @brief Same as the previous specialization but for const tuple.
82
- template <std::size_t I = 0UL , typename Callable, typename ... TypesT>
83
- COMMON_PUBLIC inline constexpr typename std::enable_if_t <I == sizeof ...(TypesT)>
84
- visit (const std::tuple<TypesT...> &, Callable) noexcept {}
88
+ template <std::size_t I = 0UL , typename Callable, typename ... TypesT>
89
+ COMMON_PUBLIC inline constexpr typename std::enable_if_t <I == sizeof ...(TypesT)> visit (
90
+ const std::tuple<TypesT...> &, Callable) noexcept
91
+ {
92
+ }
85
93
86
94
// /
87
95
// / @brief Visit every element in a tuple.
@@ -98,32 +106,37 @@ visit(const std::tuple<TypesT...> &, Callable) noexcept {}
98
106
// /
99
107
// / @return Does not return anything. Capture variables in a lambda to return any values.
100
108
// /
101
- template <std::size_t I = 0UL , typename Callable, typename ... TypesT>
102
- COMMON_PUBLIC inline constexpr typename std::enable_if_t <I != sizeof ...(TypesT)>
103
- visit ( std::tuple<TypesT...> & tuple, Callable callable) noexcept
109
+ template <std::size_t I = 0UL , typename Callable, typename ... TypesT>
110
+ COMMON_PUBLIC inline constexpr typename std::enable_if_t <I != sizeof ...(TypesT)> visit (
111
+ std::tuple<TypesT...> & tuple, Callable callable) noexcept
104
112
{
105
113
callable (std::get<I>(tuple));
106
114
visit<I + 1UL , Callable, TypesT...>(tuple, callable);
107
115
}
108
116
// / @brief Same as the previous specialization but for const tuple.
109
- template <std::size_t I = 0UL , typename Callable, typename ... TypesT>
110
- COMMON_PUBLIC inline constexpr typename std::enable_if_t <I != sizeof ...(TypesT)>
111
- visit ( const std::tuple<TypesT...> & tuple, Callable callable) noexcept
117
+ template <std::size_t I = 0UL , typename Callable, typename ... TypesT>
118
+ COMMON_PUBLIC inline constexpr typename std::enable_if_t <I != sizeof ...(TypesT)> visit (
119
+ const std::tuple<TypesT...> & tuple, Callable callable) noexcept
112
120
{
113
121
callable (std::get<I>(tuple));
114
122
visit<I + 1UL , Callable, TypesT...>(tuple, callable);
115
123
}
116
124
117
125
// / @brief A class to compute a conjunction over given traits.
118
- template <class ...>
119
- struct COMMON_PUBLIC conjunction : std::true_type {};
126
+ template <class ...>
127
+ struct COMMON_PUBLIC conjunction : std::true_type
128
+ {
129
+ };
120
130
// / @brief A conjunction of another type shall derive from that type.
121
- template <class TraitT >
122
- struct COMMON_PUBLIC conjunction<TraitT>: TraitT {};
123
- template <class TraitT , class ... TraitsTs>
131
+ template <class TraitT >
132
+ struct COMMON_PUBLIC conjunction<TraitT> : TraitT
133
+ {
134
+ };
135
+ template <class TraitT , class ... TraitsTs>
124
136
struct COMMON_PUBLIC conjunction<TraitT, TraitsTs...>
125
- : std::conditional_t <static_cast <bool >(TraitT::value), conjunction<TraitsTs...>, TraitT> {};
126
-
137
+ : std::conditional_t <static_cast <bool >(TraitT::value), conjunction<TraitsTs...>, TraitT>
138
+ {
139
+ };
127
140
128
141
// /
129
142
// / @brief A trait to check if a tuple has a type.
@@ -133,7 +146,7 @@ struct COMMON_PUBLIC conjunction<TraitT, TraitsTs...>
133
146
// / @tparam QueryT A query type.
134
147
// / @tparam TupleT A tuple to search the type in.
135
148
// /
136
- template <typename QueryT, typename TupleT>
149
+ template <typename QueryT, typename TupleT>
137
150
struct has_type ;
138
151
139
152
// /
@@ -142,8 +155,10 @@ struct has_type;
142
155
// /
143
156
// / @tparam QueryT Any type.
144
157
// /
145
- template <typename QueryT>
146
- struct has_type <QueryT, std::tuple<>>: std::false_type {};
158
+ template <typename QueryT>
159
+ struct has_type <QueryT, std::tuple<>> : std::false_type
160
+ {
161
+ };
147
162
148
163
// /
149
164
// / @brief Recursive override of the main trait.
@@ -152,8 +167,10 @@ struct has_type<QueryT, std::tuple<>>: std::false_type {};
152
167
// / @tparam HeadT Head type in the tuple.
153
168
// / @tparam TailTs Rest of the tuple types.
154
169
// /
155
- template <typename QueryT, typename HeadT, typename ... TailTs>
156
- struct has_type <QueryT, std::tuple<HeadT, TailTs...>>: has_type<QueryT, std::tuple<TailTs...>> {};
170
+ template <typename QueryT, typename HeadT, typename ... TailTs>
171
+ struct has_type <QueryT, std::tuple<HeadT, TailTs...>> : has_type<QueryT, std::tuple<TailTs...>>
172
+ {
173
+ };
157
174
158
175
// /
159
176
// / @brief End of recursion for the main `has_type` trait. Becomes a `true_type` when the first
@@ -162,9 +179,10 @@ struct has_type<QueryT, std::tuple<HeadT, TailTs...>>: has_type<QueryT, std::tup
162
179
// / @tparam QueryT Query type.
163
180
// / @tparam TailTs Other types in the tuple.
164
181
// /
165
- template <typename QueryT, typename ... TailTs>
166
- struct has_type <QueryT, std::tuple<QueryT, TailTs...>>: std::true_type {};
167
-
182
+ template <typename QueryT, typename ... TailTs>
183
+ struct has_type <QueryT, std::tuple<QueryT, TailTs...>> : std::true_type
184
+ {
185
+ };
168
186
169
187
// /
170
188
// / @brief A trait used to intersect types stored in tuples at compile time. The resulting
@@ -176,7 +194,7 @@ struct has_type<QueryT, std::tuple<QueryT, TailTs...>>: std::true_type {};
176
194
// / @tparam TupleT1 Tuple 1
177
195
// / @tparam TupleT2 Tuple 2
178
196
// /
179
- template <typename TupleT1, typename TupleT2>
197
+ template <typename TupleT1, typename TupleT2>
180
198
struct intersect
181
199
{
182
200
// /
@@ -185,18 +203,16 @@ struct intersect
185
203
// / @details This function "iterates" over the types in TupleT1 and checks if those are in
186
204
// / TupleT2. If this is true, these types are concatenated into a new tuple.
187
205
// /
188
- template <std::size_t ... Indices>
206
+ template <std::size_t ... Indices>
189
207
static constexpr auto make_intersection (std::index_sequence<Indices...>)
190
208
{
191
- return std::tuple_cat (
192
- std::conditional_t <
193
- has_type<std::tuple_element_t <Indices, TupleT1>, TupleT2>::value,
194
- std::tuple<std::tuple_element_t <Indices, TupleT1>>,
195
- std::tuple<>>{} ...);
209
+ return std::tuple_cat (std::conditional_t <
210
+ has_type<std::tuple_element_t <Indices, TupleT1>, TupleT2>::value,
211
+ std::tuple<std::tuple_element_t <Indices, TupleT1>>, std::tuple<>>{}...);
196
212
}
197
213
// / The resulting tuple type.
198
214
using type =
199
- decltype (make_intersection(std::make_index_sequence<std::tuple_size<TupleT1>::value> {}));
215
+ decltype (make_intersection(std::make_index_sequence<std::tuple_size<TupleT1>::value>{}));
200
216
};
201
217
202
218
} // namespace type_traits
0 commit comments