From 3b4c4a2667d10335a803c29e4906f27e2409ceb8 Mon Sep 17 00:00:00 2001 From: linpz Date: Tue, 24 Dec 2024 00:53:02 +0800 Subject: [PATCH 1/3] Fix std::array --- include/cereal/types/array.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/cereal/types/array.hpp b/include/cereal/types/array.hpp index 8ae2a4a0..9f6a9c03 100644 --- a/include/cereal/types/array.hpp +++ b/include/cereal/types/array.hpp @@ -45,6 +45,11 @@ namespace cereal ar( binary_data( array.data(), sizeof(array) ) ); } + template inline + typename std::enable_if, Archive>::value + && std::is_arithmetic::value, void>::type + CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::array const & array ) {} + //! Loading for std::array primitive types //! using binary serialization, if supported template inline @@ -55,6 +60,11 @@ namespace cereal ar( binary_data( array.data(), sizeof(array) ) ); } + template inline + typename std::enable_if, Archive>::value + && std::is_arithmetic::value, void>::type + CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array & array ) {} + //! Saving for std::array all other types template inline typename std::enable_if, Archive>::value From e58d69d00564151134aa5524bbbb0331b349dd97 Mon Sep 17 00:00:00 2001 From: linpz Date: Tue, 31 Dec 2024 17:10:55 +0800 Subject: [PATCH 2/3] Add unittests for std::array --- unittests/array.cpp | 12 ++++++++---- unittests/array.hpp | 22 +++++++++++----------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/unittests/array.cpp b/unittests/array.cpp index 00543fe6..78c3ef6c 100644 --- a/unittests/array.cpp +++ b/unittests/array.cpp @@ -31,22 +31,26 @@ TEST_SUITE_BEGIN("array"); TEST_CASE("binary_array") { - test_array(); + test_array(); + test_array(); } TEST_CASE("portable_binary_array") { - test_array(); + test_array(); + test_array(); } TEST_CASE("xml_array") { - test_array(); + test_array(); + test_array(); } TEST_CASE("json_array") { - test_array(); + test_array(); + test_array(); } TEST_SUITE_END(); diff --git a/unittests/array.hpp b/unittests/array.hpp index f782faab..35b50d8c 100644 --- a/unittests/array.hpp +++ b/unittests/array.hpp @@ -28,7 +28,7 @@ #define CEREAL_TEST_ARRAY_H_ #include "common.hpp" -template inline +template inline void test_array() { std::random_device rd; @@ -36,23 +36,23 @@ void test_array() for(int ii=0; ii<100; ++ii) { - std::array o_podarray; + std::array o_podarray; for(auto & elem : o_podarray) elem = random_value(gen); - std::array o_iserarray; + std::array o_iserarray; for(auto & elem : o_iserarray) elem = StructInternalSerialize( random_value(gen), random_value(gen) ); - std::array o_isplarray; + std::array o_isplarray; for(auto & elem : o_isplarray) elem = StructInternalSplit( random_value(gen), random_value(gen) ); - std::array o_eserarray; + std::array o_eserarray; for(auto & elem : o_eserarray) elem = StructExternalSerialize( random_value(gen), random_value(gen) ); - std::array o_esplarray; + std::array o_esplarray; for(auto & elem : o_esplarray) elem = StructExternalSplit( random_value(gen), random_value(gen) ); @@ -67,11 +67,11 @@ void test_array() oar(o_esplarray); } - std::array i_podarray; - std::array i_iserarray; - std::array i_isplarray; - std::array i_eserarray; - std::array i_esplarray; + std::array i_podarray; + std::array i_iserarray; + std::array i_isplarray; + std::array i_eserarray; + std::array i_esplarray; std::istringstream is(os.str()); { From 280687ce48d035ffa3f93348cbedd74679d27148 Mon Sep 17 00:00:00 2001 From: linpz Date: Mon, 6 Jan 2025 05:33:37 +0800 Subject: [PATCH 3/3] update std::array --- include/cereal/types/array.hpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/include/cereal/types/array.hpp b/include/cereal/types/array.hpp index 9f6a9c03..413d7cd5 100644 --- a/include/cereal/types/array.hpp +++ b/include/cereal/types/array.hpp @@ -42,14 +42,9 @@ namespace cereal && std::is_arithmetic::value, void>::type CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::array const & array ) { - ar( binary_data( array.data(), sizeof(array) ) ); + ar( binary_data( array.data(), N*sizeof(T) ) ); } - template inline - typename std::enable_if, Archive>::value - && std::is_arithmetic::value, void>::type - CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::array const & array ) {} - //! Loading for std::array primitive types //! using binary serialization, if supported template inline @@ -57,14 +52,9 @@ namespace cereal && std::is_arithmetic::value, void>::type CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array & array ) { - ar( binary_data( array.data(), sizeof(array) ) ); + ar( binary_data( array.data(), N*sizeof(T) ) ); } - template inline - typename std::enable_if, Archive>::value - && std::is_arithmetic::value, void>::type - CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array & array ) {} - //! Saving for std::array all other types template inline typename std::enable_if, Archive>::value