diff --git a/binary_archive/binary_archive.hpp b/binary_archive/binary_archive.hpp index 18771c91..ae8a5ceb 100644 --- a/binary_archive/binary_archive.hpp +++ b/binary_archive/binary_archive.hpp @@ -83,6 +83,20 @@ namespace cereal ar & t.value; } + template + typename std::enable_if::value, void>::type + save(BinaryOutputArchive & ar, T const & array) + { + ar.save_binary(array, traits::sizeofArray() * sizeof(typename std::remove_all_extents::type)); + } + + template + typename std::enable_if::value, void>::type + load(BinaryInputArchive & ar, T & array) + { + ar.load_binary(array, traits::sizeofArray() * sizeof(typename std::remove_all_extents::type)); + } + template void serialize( Archive & ar, T * & t ) { diff --git a/details/traits.hpp b/details/traits.hpp index a06ed9fc..479c6bb1 100644 --- a/details/traits.hpp +++ b/details/traits.hpp @@ -100,29 +100,10 @@ namespace cereal } // ###################################################################### - constexpr std::false_type is_smart_ptr(...) - { - return {}; - } - - template - constexpr std::true_type is_smart_ptr( std::unique_ptr const & p ) - { - return {}; - } - template - constexpr std::true_type is_smart_ptr( std::shared_ptr const & p ) + constexpr size_t sizeofArray( size_t rank = std::rank::value ) { - return {}; - } - - // ###################################################################### - //! Returns true if the type T is a pointer or smart pointer (in std library) - template - constexpr bool is_any_pointer() - { - return std::is_pointer() || std::is_same() ))>::value; + return rank == 0 ? 1 : std::extent::value * sizeofArray::type>( rank - 1 ); } } } diff --git a/test.cpp b/test.cpp index 579463c1..b2b45755 100644 --- a/test.cpp +++ b/test.cpp @@ -154,8 +154,8 @@ int main() archive & xptr2; archive & wptr2; archive & uptr; - } + { std::ifstream is("ptr.txt"); cereal::BinaryInputArchive archive(is); @@ -176,7 +176,34 @@ int main() std::cout << uptr->a << std::endl; } + { + std::ofstream os("arr.txt"); + cereal::BinaryOutputArchive archive(os); + int a1[] = {1, 2, 3}; + int a2[][2] = {{4, 5}, {6, 7}}; + archive & a1; + archive & a2; + } + { + std::ifstream is("arr.txt"); + cereal::BinaryInputArchive archive(is); + int a1[3]; + int a2[2][2]; + archive & a1; + archive & a2; + + for(auto i : a1) + std::cout << i << " "; + std::cout << std::endl; + for( auto const & i : a2 ) + { + for( auto j : i ) + std::cout << j << " "; + std::cout << std::endl; + } + std::cout << std::endl; + } return 0; }