Skip to content

Commit 4f060ca

Browse files
aalkinktf
authored andcommitted
C++ standard fobids specializations of is_trivially_copyable
1 parent 2b4851c commit 4f060ca

File tree

6 files changed

+20
-68
lines changed

6 files changed

+20
-68
lines changed

Common/MathUtils/include/MathUtils/Cartesian.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -284,25 +284,15 @@ GPUdi() SMatrix<T, D1, D1, MatRepSym<T, D1>> Similarity(const SMatrix<T, D1, D2,
284284
#if (!defined(GPUCA_STANDALONE) || !defined(DGPUCA_NO_ROOT)) && !defined(GPUCA_GPUCODE) && !defined(GPUCOMMONRTYPES_H_ACTIVE)
285285
std::ostream& operator<<(std::ostream& os, const o2::math_utils::Rotation2Df_t& t);
286286
std::ostream& operator<<(std::ostream& os, const o2::math_utils::Rotation2Dd_t& t);
287-
288-
namespace std
287+
namespace o2::framework
289288
{
289+
template <typename T>
290+
struct is_forced_trivially_copyable;
290291

291-
/// Defining Point3D explicitly as trivially copyable
292-
///
293-
/// std::is_trivially_copyable<ROOT::Math::Cartesian3D<T>> fails because the class
294-
/// implements a copy constructor, although it does not much more than the default copy
295-
/// constructor. We need Point3D to fulfill the condition in order to make types
296-
/// inheriting from it or using it as member can be safely detected as messageable.
297-
///
298-
/// We believe that Point3D is messageable and explicitly specialize the type trait.
299-
/// There is a unit test for checking trivial copy
300-
/// This is a workaround, we will also make suggestions to fix the cause in ROOT itself
301-
/// TODO: delete once it is fixed in ROOT
302292
template <typename T>
303-
struct is_trivially_copyable<o2::math_utils::Point3D<T>> : std::true_type {
293+
struct is_forced_trivially_copyable<o2::math_utils::Point3D<T>> : std::true_type {
304294
};
305-
} // namespace std
295+
} // namespace o2::framework
306296
#endif // Disable for GPU
307297

308298
#endif

Common/MathUtils/test/testCartesian.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(Cartesian_test)
7777
BOOST_AUTO_TEST_CASE(Point3D_messageable)
7878
{
7979
using ElementType = math_utils::Point3D<int>;
80-
static_assert(std::is_trivially_copyable<ElementType>::value == true);
80+
static_assert(o2::framework::is_forced_trivially_copyable<ElementType>::value == true);
8181
std::vector<ElementType> pts(10);
8282
auto makeElement = [](int idx) {
8383
return ElementType{idx, idx + 10, idx + 20};

Detectors/DCS/include/DetectorsDCS/DataPointCompositeObject.h

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
#include "DetectorsDCS/DataPointValue.h"
2929
#include "DetectorsDCS/DeliveryType.h"
3030

31-
namespace o2
32-
{
33-
namespace dcs
31+
namespace o2::dcs
3432
{
3533
/**
3634
* DataPointCompositeObject is a composition of a DataPointIdentifier and a
@@ -291,26 +289,6 @@ struct DataPointCompositeObject final {
291289
template <typename T>
292290
T getValue(const DataPointCompositeObject& dpcom);
293291

294-
} // namespace dcs
295-
296-
/// Defining DataPointCompositeObject explicitly as messageable
297-
namespace framework
298-
{
299-
template <typename T>
300-
struct is_messageable;
301-
template <>
302-
struct is_messageable<o2::dcs::DataPointCompositeObject> : std::true_type {
303-
};
304-
} // namespace framework
305-
306-
} // namespace o2
307-
308-
/// Defining DataPointCompositeObject explicitly as copiable
309-
namespace std
310-
{
311-
template <>
312-
struct is_trivially_copyable<o2::dcs::DataPointCompositeObject> : std::true_type {
313-
};
314-
} // namespace std
292+
} // namespace o2::dcs
315293

316294
#endif /* O2_DCS_DATAPOINT_COMPOSITE_OBJECT_H */

Detectors/DCS/include/DetectorsDCS/DataPointIdentifier.h

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
#include "DetectorsDCS/GenericFunctions.h"
3232
#include "DetectorsDCS/DeliveryType.h"
3333

34-
namespace o2
35-
{
36-
namespace dcs
34+
namespace o2::dcs
3735
{
3836
/**
3937
* DataPointIdentifier object is responsible for storing the alias and type
@@ -208,19 +206,7 @@ struct DPIDHash {
208206
return dpid.hash_code();
209207
}
210208
};
211-
} // namespace dcs
212-
213-
/// Defining DataPointIdentifier explicitly as messageable
214-
namespace framework
215-
{
216-
template <typename T>
217-
struct is_messageable;
218-
template <>
219-
struct is_messageable<o2::dcs::DataPointIdentifier> : std::true_type {
220-
};
221-
} // namespace framework
222-
223-
} // namespace o2
209+
} // namespace o2::dcs
224210

225211
// specailized std::hash
226212
namespace std
@@ -232,11 +218,6 @@ struct hash<o2::dcs::DataPointIdentifier> {
232218
return std::hash<uint64_t>{}(dpid.hash_code());
233219
}
234220
};
235-
236-
template <>
237-
struct is_trivially_copyable<o2::dcs::DataPointIdentifier> : std::true_type {
238-
};
239-
240221
} // namespace std
241222

242223
#endif /* O2_DCS_DATAPOINT_IDENTIFIER_H */

Detectors/DCS/test/testDataPointTypes.cxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@
1717
#include <boost/test/unit_test.hpp>
1818
#include "DetectorsDCS/DataPointCompositeObject.h"
1919
#include "Framework/TypeTraits.h"
20-
#include <vector>
21-
#include <list>
2220
#include <gsl/gsl>
2321
#include <boost/mpl/list.hpp>
2422

2523
typedef boost::mpl::list<o2::dcs::DataPointIdentifier, o2::dcs::DataPointValue, o2::dcs::DataPointCompositeObject> testTypes;
2624

2725
BOOST_AUTO_TEST_CASE_TEMPLATE(DataPointCompositeObjectTypeTraits, T, testTypes)
2826
{
29-
BOOST_CHECK_EQUAL(std::is_trivially_copyable<T>::value, true);
27+
BOOST_CHECK_EQUAL(std::is_trivially_copyable_v<T>, true);
3028
BOOST_CHECK_EQUAL(std::is_polymorphic<T>::value, false);
3129
BOOST_CHECK_EQUAL(std::is_pointer<T>::value, false);
3230
BOOST_CHECK_EQUAL(o2::framework::is_forced_non_messageable<T>::value, false);

Framework/Core/include/Framework/TypeTraits.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ struct is_forced_non_messageable<
3838
typename std::enable_if<std::is_same<typename T::non_messageable, MarkAsNonMessageable>::value>::type> : public std::true_type {
3939
};
4040

41+
template <typename T>
42+
struct is_forced_trivially_copyable : std::false_type {
43+
};
44+
4145
// TODO: extend this to exclude structs with pointer data members
4246
// see e.g. https://stackoverflow.com/questions/32880990/how-to-check-if-class-has-pointers-in-c14
4347
template <typename T>
44-
struct is_messageable : std::conditional<std::is_trivially_copyable<T>::value && //
45-
!std::is_polymorphic<T>::value && //
46-
!std::is_pointer<T>::value && //
47-
!is_forced_non_messageable<T>::value, //
48+
struct is_messageable : std::conditional<(std::is_trivially_copyable<T>::value || //
49+
framework::is_forced_trivially_copyable<T>::value) && //
50+
!std::is_polymorphic<T>::value && //
51+
!std::is_pointer<T>::value && //
52+
!is_forced_non_messageable<T>::value, //
4853
std::true_type,
4954
std::false_type>::type {
5055
};

0 commit comments

Comments
 (0)