| 1 | // Copyright 2023 Peter Dimov |
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // https://www.boost.org/LICENSE_1_0.txt |
| 4 | |
| 5 | #if defined(__clang__) && defined(__has_warning) |
| 6 | # if __has_warning( "-Wdeprecated-copy" ) |
| 7 | # pragma clang diagnostic ignored "-Wdeprecated-copy" |
| 8 | # endif |
| 9 | #endif |
| 10 | |
| 11 | #include <boost/core/serialization.hpp> |
| 12 | |
| 13 | struct X |
| 14 | { |
| 15 | int a, b; |
| 16 | |
| 17 | template<class Ar> void serialize( Ar& ar, unsigned /*v*/ ) |
| 18 | { |
| 19 | ar & boost::core::make_nvp( n: "a" , v&: a ); |
| 20 | ar & boost::core::make_nvp( n: "b" , v&: b ); |
| 21 | } |
| 22 | }; |
| 23 | |
| 24 | #include <boost/archive/xml_oarchive.hpp> |
| 25 | #include <boost/archive/xml_iarchive.hpp> |
| 26 | #include <boost/core/lightweight_test.hpp> |
| 27 | #include <sstream> |
| 28 | #include <string> |
| 29 | |
| 30 | int main() |
| 31 | { |
| 32 | std::ostringstream os; |
| 33 | |
| 34 | X x1 = { .a: 7, .b: 11 }; |
| 35 | |
| 36 | { |
| 37 | boost::archive::xml_oarchive ar( os ); |
| 38 | ar << boost::core::make_nvp( n: "x1" , v&: x1 ); |
| 39 | } |
| 40 | |
| 41 | std::string s = os.str(); |
| 42 | |
| 43 | X x2 = { .a: 0, .b: 0 }; |
| 44 | |
| 45 | { |
| 46 | std::istringstream is( s ); |
| 47 | boost::archive::xml_iarchive ar( is ); |
| 48 | ar >> boost::make_nvp( n: "x2" , v&: x2 ); |
| 49 | } |
| 50 | |
| 51 | BOOST_TEST_EQ( x1.a, x2.a ); |
| 52 | BOOST_TEST_EQ( x1.b, x2.b ); |
| 53 | |
| 54 | return boost::report_errors(); |
| 55 | } |
| 56 | |