Skip to content

Commit 75cf2db

Browse files
committed
C++ standard fobids specializations of is_trivially_copyable
1 parent 757173b commit 75cf2db

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

Common/MathUtils/include/MathUtils/Cartesian.h

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -284,25 +284,14 @@ 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+
namespace o2::framework {
288+
template <typename T>
289+
struct is_forced_trivially_copyable;
287290

288-
namespace std
289-
{
290-
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
302291
template <typename T>
303-
struct is_trivially_copyable<o2::math_utils::Point3D<T>> : std::true_type {
292+
struct is_forced_trivially_copyable<o2::math_utils::Point3D<T>> : std::true_type {
304293
};
305-
} // namespace std
294+
} // namespace o2::framework
306295
#endif // Disable for GPU
307296

308297
#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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,13 @@ struct is_messageable<o2::dcs::DataPointCompositeObject> : std::true_type {
312312
} // namespace o2
313313

314314
/// Defining DataPointCompositeObject explicitly as copiable
315-
namespace std
316-
{
315+
namespace o2::framework {
316+
template <typename T>
317+
struct is_forced_trivially_copyable;
318+
317319
template <>
318-
struct is_trivially_copyable<o2::dcs::DataPointCompositeObject> : std::true_type {
320+
struct is_forced_trivially_copyable<o2::dcs::DataPointCompositeObject> : std::true_type {
319321
};
320-
} // namespace std
322+
} // namespace o2::framework
321323

322324
#endif /* O2_DCS_DATAPOINT_COMPOSITE_OBJECT_H */

Detectors/DCS/include/DetectorsDCS/DataPointIdentifier.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,15 @@ struct hash<o2::dcs::DataPointIdentifier> {
243243
return std::hash<uint64_t>{}(dpid.hash_code());
244244
}
245245
};
246+
} // namespace std
247+
namespace o2::framework {
248+
template <typename T>
249+
struct is_forced_trivially_copyable;
246250

247251
template <>
248-
struct is_trivially_copyable<o2::dcs::DataPointIdentifier> : std::true_type {
252+
struct is_forced_trivially_copyable<o2::dcs::DataPointIdentifier> : std::true_type {
249253
};
250254

251-
} // namespace std
255+
} // namespace o2::framework
252256

253257
#endif /* O2_DCS_DATAPOINT_IDENTIFIER_H */

Detectors/DCS/test/testDataPointTypes.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef boost::mpl::list<o2::dcs::DataPointIdentifier, o2::dcs::DataPointValue,
2626

2727
BOOST_AUTO_TEST_CASE_TEMPLATE(DataPointCompositeObjectTypeTraits, T, testTypes)
2828
{
29-
BOOST_CHECK_EQUAL(std::is_trivially_copyable<T>::value, true);
29+
BOOST_CHECK_EQUAL(o2::framework::is_forced_trivially_copyable<T>::value, true);
3030
BOOST_CHECK_EQUAL(std::is_polymorphic<T>::value, false);
3131
BOOST_CHECK_EQUAL(std::is_pointer<T>::value, false);
3232
BOOST_CHECK_EQUAL(o2::framework::is_forced_non_messageable<T>::value, false);

Framework/Core/include/Framework/TypeTraits.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ 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 && //
48+
struct is_messageable : std::conditional<(std::is_trivially_copyable<T>::value || //
49+
framework::is_forced_trivially_copyable<T>::value) && //
4550
!std::is_polymorphic<T>::value && //
4651
!std::is_pointer<T>::value && //
4752
!is_forced_non_messageable<T>::value, //

0 commit comments

Comments
 (0)