// Copyright 2019 Hans Dembinski // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include #include #include #include #include "std_ostream.hpp" #include "throw_exception.hpp" namespace dtl = boost::histogram::detail; namespace ba = boost::archive; template struct dummy_array_wrapper { T* ptr; std::size_t size; template void serialize(Archive& ar, unsigned /* version */) { for (auto&& x : dtl::make_span(ptr, size)) ar& x; } }; template void run_tests() { std::vector v = {{1, 2, 3}}; std::stringstream os1; { OArchive oa(os1); auto w = dtl::make_array_wrapper(v.data(), v.size()); oa << w; } std::ostringstream os2; { OArchive oa(os2); auto w = dummy_array_wrapper{v.data(), v.size()}; oa << w; } BOOST_TEST_EQ(os1.str(), os2.str()); std::vector v2(3, 0); { IArchive ia(os1); auto w = dtl::make_array_wrapper(v2.data(), v2.size()); ia >> w; } BOOST_TEST_EQ(v, v2); } int main() { BOOST_TEST(dtl::has_array_optimization::value); BOOST_TEST(dtl::has_array_optimization::value); BOOST_TEST_NOT(dtl::has_array_optimization::value); BOOST_TEST_NOT(dtl::has_array_optimization::value); run_tests(); run_tests(); return boost::report_errors(); }