From 298af49d4ed4e266bb19cd5c1a8a46ec41393309 Mon Sep 17 00:00:00 2001 From: Matthew Whitlock Date: Tue, 24 Sep 2024 19:59:37 -0400 Subject: [PATCH] #369 Implement checkpoint::is_footprinter<> --- src/checkpoint/container/atomic_serialize.h | 2 +- src/checkpoint/container/function_serialize.h | 5 +---- .../container/kokkos_unordered_map_serialize.h | 4 ++-- src/checkpoint/container/list_serialize.h | 6 +++--- src/checkpoint/container/map_serialize.h | 4 ++-- src/checkpoint/container/queue_serialize.h | 2 +- src/checkpoint/container/raw_ptr_serialize.h | 7 ++----- src/checkpoint/container/shared_ptr_serialize.h | 5 +---- src/checkpoint/container/thread_serialize.h | 2 +- src/checkpoint/container/vector_serialize.h | 10 +++++----- src/checkpoint/serializers/footprinter.h | 14 ++++++++++++++ tests/unit/test_footprinter.cc | 5 +---- 12 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/checkpoint/container/atomic_serialize.h b/src/checkpoint/container/atomic_serialize.h index f8dff0cf..e1bc80e3 100644 --- a/src/checkpoint/container/atomic_serialize.h +++ b/src/checkpoint/container/atomic_serialize.h @@ -54,7 +54,7 @@ template < typename SerializerT, typename T, typename = std::enable_if_t< - std::is_same::value + checkpoint::is_footprinter_v > > void serialize(SerializerT& s, const std::atomic& atomic) { diff --git a/src/checkpoint/container/function_serialize.h b/src/checkpoint/container/function_serialize.h index 156794df..6a192fee 100644 --- a/src/checkpoint/container/function_serialize.h +++ b/src/checkpoint/container/function_serialize.h @@ -68,10 +68,7 @@ template < typename Res, typename... ArgTypes, typename = std::enable_if_t< - std::is_same< - SerializerT, - checkpoint::Footprinter - >::value + checkpoint::is_footprinter_v > > void serializeFunction(SerializerT& s, std::function& fn) { diff --git a/src/checkpoint/container/kokkos_unordered_map_serialize.h b/src/checkpoint/container/kokkos_unordered_map_serialize.h index 8b9bf4a7..81183452 100644 --- a/src/checkpoint/container/kokkos_unordered_map_serialize.h +++ b/src/checkpoint/container/kokkos_unordered_map_serialize.h @@ -117,7 +117,7 @@ template < typename Hasher, typename EqualTo > typename std::enable_if_t< - not std::is_same::value, void + not checkpoint::is_footprinter_v, void > serialize( SerializerT& s, Kokkos::UnorderedMap& map @@ -140,7 +140,7 @@ template < typename Hasher, typename EqualTo > typename std::enable_if_t< - std::is_same::value, void + checkpoint::is_footprinter_v, void > serialize( SerializerT& s, Kokkos::UnorderedMap& map diff --git a/src/checkpoint/container/list_serialize.h b/src/checkpoint/container/list_serialize.h index c54df1c5..262a08d5 100644 --- a/src/checkpoint/container/list_serialize.h +++ b/src/checkpoint/container/list_serialize.h @@ -56,7 +56,7 @@ namespace checkpoint { template inline typename std::enable_if_t< - not std::is_same::value, void + not checkpoint::is_footprinter_v, void > deserializeOrderedElems( Serializer& s, ContainerT& cont, typename ContainerT::size_type size, @@ -76,7 +76,7 @@ deserializeOrderedElems( template inline typename std::enable_if_t< - not std::is_same::value, void + not checkpoint::is_footprinter_v, void > deserializeOrderedElems( Serializer& s, ContainerT& cont, typename ContainerT::size_type size, @@ -96,7 +96,7 @@ deserializeOrderedElems( template inline typename std::enable_if_t< - std::is_same::value, void + checkpoint::is_footprinter_v, void > deserializeOrderedElems( Serializer&, ContainerT&, typename ContainerT::size_type diff --git a/src/checkpoint/container/map_serialize.h b/src/checkpoint/container/map_serialize.h index 26dd9ee9..a1a2a880 100644 --- a/src/checkpoint/container/map_serialize.h +++ b/src/checkpoint/container/map_serialize.h @@ -58,7 +58,7 @@ namespace checkpoint { template inline typename std::enable_if_t< - not std::is_same::value, + not checkpoint::is_footprinter_v, void > deserializeEmplaceElems( Serializer& s, ContainerT& cont, typename ContainerT::size_type size @@ -77,7 +77,7 @@ inline typename std::enable_if_t< template inline typename std::enable_if_t< - std::is_same::value, + checkpoint::is_footprinter_v, void > deserializeEmplaceElems( Serializer&, ContainerT&, typename ContainerT::size_type diff --git a/src/checkpoint/container/queue_serialize.h b/src/checkpoint/container/queue_serialize.h index 25c51658..485fbccc 100644 --- a/src/checkpoint/container/queue_serialize.h +++ b/src/checkpoint/container/queue_serialize.h @@ -108,7 +108,7 @@ template < typename SerializerT, typename Q, typename = std::enable_if_t< - std::is_same_v + checkpoint::is_footprinter_v > > void serializeQueueLikeContainer(SerializerT& s, const Q& q) { diff --git a/src/checkpoint/container/raw_ptr_serialize.h b/src/checkpoint/container/raw_ptr_serialize.h index ec38c4cd..30814ad9 100644 --- a/src/checkpoint/container/raw_ptr_serialize.h +++ b/src/checkpoint/container/raw_ptr_serialize.h @@ -61,10 +61,7 @@ template < typename SerializerT, typename T, typename = std::enable_if_t< - std::is_same< - SerializerT, - checkpoint::Footprinter - >::value + checkpoint::is_footprinter_v > > void serialize(SerializerT& s, T* ptr) { @@ -95,7 +92,7 @@ void serializeRawPtr(SerializerT& s, void* ptr) { #define CHECKPOINT_FOOTPRINT_PIMPL_WITH_SIZEOF_PTR(PIMPL_TYPE) \ template < \ typename SerializerT, \ - typename = std::enable_if_t< std::is_same::value > \ + typename = std::enable_if_t< checkpoint::is_footprinter_v > \ > \ void serialize(SerializerT &s, PIMPL_TYPE *t) { \ s.countBytes(t); \ diff --git a/src/checkpoint/container/shared_ptr_serialize.h b/src/checkpoint/container/shared_ptr_serialize.h index 5f61ff46..db854b52 100644 --- a/src/checkpoint/container/shared_ptr_serialize.h +++ b/src/checkpoint/container/shared_ptr_serialize.h @@ -52,10 +52,7 @@ template < typename SerializerT, typename T, typename = std::enable_if_t< - std::is_same< - SerializerT, - checkpoint::Footprinter - >::value + checkpoint::is_footprinter_v > > void serialize(SerializerT& s, std::shared_ptr& ptr) { diff --git a/src/checkpoint/container/thread_serialize.h b/src/checkpoint/container/thread_serialize.h index 8605db35..d2596a18 100644 --- a/src/checkpoint/container/thread_serialize.h +++ b/src/checkpoint/container/thread_serialize.h @@ -53,7 +53,7 @@ namespace checkpoint { template < typename SerializerT, typename = std::enable_if_t< - std::is_same::value + checkpoint::is_footprinter_v > > void serialize(SerializerT& s, const std::thread& t) { diff --git a/src/checkpoint/container/vector_serialize.h b/src/checkpoint/container/vector_serialize.h index fa524f8a..ed4478c6 100644 --- a/src/checkpoint/container/vector_serialize.h +++ b/src/checkpoint/container/vector_serialize.h @@ -56,7 +56,7 @@ namespace checkpoint { template typename std::enable_if_t< - not std::is_same::value, SerialSizeType + not checkpoint::is_footprinter_v, SerialSizeType > serializeVectorMeta(SerializerT& s, std::vector& vec) { SerialSizeType vec_capacity = vec.capacity(); @@ -108,7 +108,7 @@ void constructVectorData( template typename std::enable_if_t< - not std::is_same::value, void + not checkpoint::is_footprinter_v, void > serialize(SerializerT& s, std::vector& vec) { auto const vec_size = serializeVectorMeta(s, vec); @@ -122,7 +122,7 @@ serialize(SerializerT& s, std::vector& vec) { template typename std::enable_if_t< - not std::is_same::value, void + not checkpoint::is_footprinter_v, void > serialize(SerializerT& s, std::vector& vec) { auto const vec_size = serializeVectorMeta(s, vec); @@ -146,7 +146,7 @@ serialize(SerializerT& s, std::vector& vec) { template typename std::enable_if_t< - std::is_same::value, void + checkpoint::is_footprinter_v, void > serialize(SerializerT& s, std::vector& vec) { s.countBytes(vec); @@ -156,7 +156,7 @@ serialize(SerializerT& s, std::vector& vec) { template typename std::enable_if_t< - std::is_same::value, void + checkpoint::is_footprinter_v, void > serialize(SerializerT& s, std::vector& vec) { s.countBytes(vec); diff --git a/src/checkpoint/serializers/footprinter.h b/src/checkpoint/serializers/footprinter.h index 120025dc..84c260a8 100644 --- a/src/checkpoint/serializers/footprinter.h +++ b/src/checkpoint/serializers/footprinter.h @@ -72,6 +72,20 @@ struct Footprinter : BaseSerializer { SerialSizeType num_bytes_ = 0; }; +namespace { + template + struct is_footprinter_impl : public std::false_type {}; + + template <> + struct is_footprinter_impl : public std::true_type {}; +} + +template +using is_footprinter = is_footprinter_impl>; + +template +static constexpr const bool is_footprinter_v = is_footprinter::value; + } /* end namespace checkpoint */ #endif /*INCLUDED_SRC_CHECKPOINT_SERIALIZERS_FOOTPRINTER_H*/ diff --git a/tests/unit/test_footprinter.cc b/tests/unit/test_footprinter.cc index 3a2fc402..993b3fb4 100644 --- a/tests/unit/test_footprinter.cc +++ b/tests/unit/test_footprinter.cc @@ -105,10 +105,7 @@ struct TestDerived2 : TestBase { template < typename SerializerT, typename = std::enable_if_t< - std::is_same< - SerializerT, - checkpoint::Footprinter - >::value + checkpoint::is_footprinter_v > > void serialize(SerializerT& s) {