Skip to content

Commit d14b9e0

Browse files
committed
DPL: add is_specialization_v
1 parent 78067b5 commit d14b9e0

9 files changed

Lines changed: 35 additions & 31 deletions

File tree

Framework/Core/include/Framework/ASoA.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ using is_soa_iterator_t = typename framework::is_base_of_template<RowViewCore, T
896896
template <typename T>
897897
constexpr bool is_soa_iterator_v()
898898
{
899-
return is_soa_iterator_t<T>::value || framework::is_specialization<T, RowViewCore>::value;
899+
return is_soa_iterator_t<T>::value || framework::is_specialization_v<T, RowViewCore>;
900900
}
901901

902902
template <typename T>
@@ -1991,10 +1991,10 @@ struct Concat : ConcatBase<T1, T2> {
19911991
};
19921992

19931993
template <typename T>
1994-
using is_soa_join_t = typename framework::is_specialization<T, soa::Join>;
1994+
inline constexpr bool is_soa_join_v = framework::is_specialization_v<T, soa::Join>;
19951995

19961996
template <typename T>
1997-
using is_soa_concat_t = typename framework::is_specialization<T, soa::Concat>;
1997+
inline constexpr bool is_soa_concat_v = framework::is_specialization_v<T, soa::Concat>;
19981998

19991999
template <typename T>
20002000
class FilteredBase : public T

Framework/Core/include/Framework/DataAllocator.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class DataAllocator
104104
template <typename T, typename... Args>
105105
decltype(auto) make(const Output& spec, Args... args)
106106
{
107-
if constexpr (is_specialization<T, UninitializedVector>::value) {
107+
if constexpr (is_specialization_v<T, UninitializedVector>) {
108108
// plain buffer as polymorphic spectator std::vector, which does not run constructors / destructors
109109
using ValueType = typename T::value_type;
110110
auto& timingInfo = mRegistry->get<TimingInfo>();
@@ -116,7 +116,7 @@ class DataAllocator
116116
return context.add<MessageContext::VectorObject<ValueType, MessageContext::ContainerRefObject<std::vector<ValueType, o2::pmr::NoConstructAllocator<ValueType>>>>>(
117117
std::move(headerMessage), channel, 0, std::forward<Args>(args)...)
118118
.get();
119-
} else if constexpr (is_specialization<T, std::vector>::value && has_messageable_value_type<T>::value) {
119+
} else if constexpr (is_specialization_v<T, std::vector> && has_messageable_value_type<T>::value) {
120120
// this catches all std::vector objects with messageable value type before checking if is also
121121
// has a root dictionary, so non-serialized transmission is preferred
122122
using ValueType = typename T::value_type;
@@ -160,9 +160,9 @@ class DataAllocator
160160
constexpr bool isBoostSerializable = framework::is_boost_serializable<T>::value;
161161
if constexpr (is_messageable<T>::value == true) {
162162
return *reinterpret_cast<T*>(newChunk(spec, sizeof(T)).data());
163-
} else if constexpr (is_specialization<T, BoostSerialized>::value == true) {
163+
} else if constexpr (is_specialization_v<T, BoostSerialized> == true) {
164164
return make_boost<typename T::wrapped_type>(std::move(spec));
165-
} else if constexpr (is_specialization<T, BoostSerialized>::value == false && isBoostSerializable == true && std::is_base_of<std::string, T>::value == false) {
165+
} else if constexpr (is_specialization_v<T, BoostSerialized> == false && isBoostSerializable == true && std::is_base_of<std::string, T>::value == false) {
166166
return make_boost<T>(std::move(spec));
167167
} else {
168168
static_assert(always_static_assert_v<T>, ERROR_STRING);
@@ -187,7 +187,7 @@ class DataAllocator
187187
create(spec, &writer, schema);
188188
return writer;
189189
}
190-
} else if constexpr (is_specialization<T, BoostSerialized>::value) {
190+
} else if constexpr (is_specialization_v<T, BoostSerialized>) {
191191
return make_boost<FirstArg>(std::move(spec));
192192
} else {
193193
static_assert(always_static_assert_v<T>, ERROR_STRING);
@@ -227,7 +227,7 @@ class DataAllocator
227227
/// Adopt a raw buffer in the framework and serialize / send
228228
/// it to the consumers of @a spec once done.
229229
template <typename T>
230-
typename std::enable_if<is_specialization<T, BoostSerialized>::value == true, void>::type
230+
typename std::enable_if<is_specialization_v<T, BoostSerialized> == true, void>::type
231231
adopt(const Output& spec, T* ptr)
232232
{
233233
adopt_boost(std::move(spec), std::move(ptr()));
@@ -289,7 +289,7 @@ class DataAllocator
289289
memcpy(payloadMessage->GetData(), &object, sizeof(T));
290290

291291
serializationType = o2::header::gSerializationMethodNone;
292-
} else if constexpr (is_specialization<T, std::vector>::value == true ||
292+
} else if constexpr (is_specialization_v<T, std::vector> == true ||
293293
(gsl::details::is_span<T>::value && has_messageable_value_type<T>::value)) {
294294
using ElementType = typename std::remove_pointer<typename T::value_type>::type;
295295
if constexpr (is_messageable<ElementType>::value) {
@@ -324,10 +324,10 @@ class DataAllocator
324324
"\n - pointers to those"
325325
"\n - types with ROOT dictionary and implementing ROOT ClassDef interface");
326326
}
327-
} else if constexpr (has_root_dictionary<T>::value == true || is_specialization<T, ROOTSerialized>::value == true) {
327+
} else if constexpr (has_root_dictionary<T>::value == true || is_specialization_v<T, ROOTSerialized> == true) {
328328
// Serialize a snapshot of an object with root dictionary
329329
payloadMessage = proxy.createMessage();
330-
if constexpr (is_specialization<T, ROOTSerialized>::value == true) {
330+
if constexpr (is_specialization_v<T, ROOTSerialized> == true) {
331331
// Explicitely ROOT serialize a snapshot of object.
332332
// An object wrapped into type `ROOTSerialized` is explicitely marked to be ROOT serialized
333333
// and is expected to have a ROOT dictionary. Availability can not be checked at compile time

Framework/Core/include/Framework/DataRefUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ struct DataRefUtils {
119119
});
120120

121121
return std::move(result);
122-
} else if constexpr (is_specialization<T, ROOTSerialized>::value == true) {
122+
} else if constexpr (is_specialization_v<T, ROOTSerialized> == true) {
123123
// See above. SFINAE allows us to use this to extract a ROOT-serialized object
124124
// with a somewhat uniform API. ROOT serialization method is enforced by using
125125
// type wrapper @a ROOTSerialized
@@ -151,7 +151,7 @@ struct DataRefUtils {
151151
}
152152
});
153153
return std::move(result);
154-
} else if constexpr (is_specialization<T, CCDBSerialized>::value == true) {
154+
} else if constexpr (is_specialization_v<T, CCDBSerialized> == true) {
155155
using wrapped = typename T::wrapped_type;
156156
using DataHeader = o2::header::DataHeader;
157157
std::unique_ptr<wrapped> result(static_cast<wrapped*>(DataRefUtils::decodeCCDB(ref, typeid(wrapped))));

Framework/Core/include/Framework/GroupSlicer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct GroupSlicer {
7373
constexpr auto index = framework::has_type_at_v<std::decay_t<T>>(associated_pack_t{});
7474
if constexpr (relatedByIndex<std::decay_t<G>, std::decay_t<T>>()) {
7575
auto name = getLabelFromType<std::decay_t<T>>();
76-
if constexpr (!framework::is_specialization<std::decay_t<T>, soa::SmallGroups>::value) {
76+
if constexpr (!framework::is_specialization_v<std::decay_t<T>, soa::SmallGroups>) {
7777
if (table.size() == 0) {
7878
return;
7979
}
@@ -279,7 +279,7 @@ struct GroupSlicer {
279279
} else {
280280
pos = position;
281281
}
282-
if constexpr (!framework::is_specialization<std::decay_t<A1>, soa::SmallGroups>::value) {
282+
if constexpr (!framework::is_specialization_v<std::decay_t<A1>, soa::SmallGroups>) {
283283
if (originalTable.size() == 0) {
284284
return originalTable;
285285
}

Framework/Core/include/Framework/InputRecord.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,14 @@ class InputRecord
255255
return std::make_unique<TableConsumer>(data, DataRefUtils::getPayloadSize(ref));
256256

257257
// implementation (e)
258-
} else if constexpr (framework::is_boost_serializable<T>::value || is_specialization<T, BoostSerialized>::value) {
258+
} else if constexpr (framework::is_boost_serializable<T>::value || is_specialization_v<T, BoostSerialized>) {
259259
// substitution for boost-serialized entities
260260
// We have to deserialize the ostringstream.
261261
// FIXME: check that the string is null terminated.
262262
// @return deserialized copy of payload
263263
auto str = std::string(ref.payload, DataRefUtils::getPayloadSize(ref));
264264
assert(DataRefUtils::getPayloadSize(ref) == sizeof(T));
265-
if constexpr (is_specialization<T, BoostSerialized>::value) {
265+
if constexpr (is_specialization_v<T, BoostSerialized>) {
266266
return o2::utils::BoostDeserialize<typename T::wrapped_type>(str);
267267
} else {
268268
return o2::utils::BoostDeserialize<T>(str);
@@ -291,7 +291,7 @@ class InputRecord
291291
// implementation (g)
292292
} else if constexpr (is_container<T>::value) {
293293
// currently implemented only for vectors
294-
if constexpr (is_specialization<typename std::remove_const<T>::type, std::vector>::value) {
294+
if constexpr (is_specialization_v<std::remove_const_t<T>, std::vector>) {
295295
auto header = DataRefUtils::getHeader<header::DataHeader*>(ref);
296296
auto payloadSize = DataRefUtils::getPayloadSize(ref);
297297
auto method = header->payloadSerializationMethod;
@@ -309,7 +309,7 @@ class InputRecord
309309
/// container, C++11 and beyond will implicitly apply return value optimization.
310310
/// @return std container object
311311
using NonConstT = typename std::remove_const<T>::type;
312-
if constexpr (is_specialization<T, ROOTSerialized>::value == true || has_root_dictionary<T>::value == true) {
312+
if constexpr (is_specialization_v<T, ROOTSerialized> == true || has_root_dictionary<T>::value == true) {
313313
// we expect the unique_ptr to hold an object, exception should have been thrown
314314
// otherwise
315315
auto object = DataRefUtils::as<NonConstT>(ref);
@@ -362,7 +362,7 @@ class InputRecord
362362
// return type with non-owning Deleter instance
363363
std::unique_ptr<ValueT const, Deleter<ValueT const>> result(ptr, Deleter<ValueT const>(false));
364364
return result;
365-
} else if constexpr (is_specialization<ValueT, std::vector>::value && has_messageable_value_type<ValueT>::value) {
365+
} else if constexpr (is_specialization_v<ValueT, std::vector> && has_messageable_value_type<ValueT>::value) {
366366
// TODO: construct a vector spectator
367367
// this is a quick solution now which makes a copy of the plain vector data
368368
auto* start = reinterpret_cast<typename ValueT::value_type const*>(ref.payload);

Framework/Core/test/test_TypeTraits.cxx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ BOOST_AUTO_TEST_CASE(TestIsSpecialization)
3636
std::list<int> c;
3737
int d;
3838

39-
bool test1 = is_specialization<decltype(a), std::vector>::value;
40-
bool test2 = is_specialization<decltype(b), std::vector>::value;
41-
bool test3 = is_specialization<decltype(b), std::list>::value;
42-
bool test4 = is_specialization<decltype(c), std::list>::value;
43-
bool test5 = is_specialization<decltype(c), std::vector>::value;
44-
bool test6 = is_specialization<decltype(d), std::vector>::value;
39+
bool test1 = is_specialization_v<decltype(a), std::vector>;
40+
bool test2 = is_specialization_v<decltype(b), std::vector>;
41+
bool test3 = is_specialization_v<decltype(b), std::list>;
42+
bool test4 = is_specialization_v<decltype(c), std::list>;
43+
bool test5 = is_specialization_v<decltype(c), std::vector>;
44+
bool test6 = is_specialization_v<decltype(d), std::vector>;
4545
BOOST_REQUIRE_EQUAL(test1, true);
4646
BOOST_REQUIRE_EQUAL(test2, true);
4747
BOOST_REQUIRE_EQUAL(test3, false);
@@ -50,7 +50,7 @@ BOOST_AUTO_TEST_CASE(TestIsSpecialization)
5050
BOOST_REQUIRE_EQUAL(test6, false);
5151

5252
ROOTSerialized<decltype(d)> e(d);
53-
bool test7 = is_specialization<decltype(e), ROOTSerialized>::value;
53+
bool test7 = is_specialization_v<decltype(e), ROOTSerialized>;
5454
BOOST_REQUIRE_EQUAL(test7, true);
5555
}
5656

Framework/Foundation/include/Framework/Traits.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ template <template <typename...> class Ref, typename... Args>
2727
struct is_specialization<Ref<Args...>, Ref> : std::true_type {
2828
};
2929

30+
template <typename T, template <typename...> class Ref>
31+
inline constexpr bool is_specialization_v = is_specialization<T, Ref>::value;
32+
3033
template <typename A, typename B>
3134
struct is_overriding : public std::bool_constant<std::is_same_v<A, B> == false && std::is_member_function_pointer_v<A> && std::is_member_function_pointer_v<B>> {
3235
};

Framework/Utils/include/DPLUtils/RootTreeReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ class GenericRootTreeReader
510510
mPublishingMode = def;
511511
} else if constexpr (std::is_same<U, SpecialPublishHook*>::value) {
512512
mPublishHook = def;
513-
} else if constexpr (is_specialization<U, BranchDefinition>::value) {
513+
} else if constexpr (is_specialization_v<U, BranchDefinition>) {
514514
cargs.emplace_back(key_type(def.key), def.name);
515515
using type = BranchConfigurationElement<typename U::type, BASE>;
516516
return std::move(createBranchConfiguration<0, type>(std::move(cargs), std::forward<Args>(args)...));

Framework/Utils/include/DPLUtils/RootTreeWriter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ class RootTreeWriter
502502
// vectors of messageable types
503503
template <typename T>
504504
struct StructureElementTypeTrait<T, std::enable_if_t<has_messageable_value_type<T>::value &&
505-
is_specialization<T, std::vector>::value>> {
505+
is_specialization_v<T, std::vector>>> {
506506
using value_type = T;
507507
using store_type = value_type*;
508508
using specialization_id = MessageableVectorSpecialization;
@@ -520,7 +520,8 @@ class RootTreeWriter
520520

521521
// types marked as ROOT serialized
522522
template <typename T>
523-
struct StructureElementTypeTrait<T, std::enable_if_t<is_specialization<T, ROOTSerialized>::value == true>> {
523+
struct StructureElementTypeTrait<T,
524+
std::enable_if_t<is_specialization_v<T, ROOTSerialized> == true>> {
524525
using value_type = typename T::wrapped_type;
525526
using store_type = value_type*;
526527
using specialization_id = ROOTTypeSpecialization;

0 commit comments

Comments
 (0)