]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/histogram/examples/guide_histogram_serialization.cpp
1 // Copyright 2015-2018 Hans Dembinski
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
7 //[ guide_histogram_serialization
9 #include <boost/archive/text_iarchive.hpp>
10 #include <boost/archive/text_oarchive.hpp>
11 #include <boost/histogram.hpp>
12 #include <boost/histogram/serialization.hpp> // includes serialization code
17 using namespace boost::histogram
;
19 auto a
= make_histogram(axis::regular
<>(3, -1.0, 1.0, "axis 0"),
20 axis::integer
<>(0, 2, "axis 1"));
23 std::string buf
; // to hold persistent representation
27 std::ostringstream os
;
28 boost::archive::text_oarchive
oa(os
);
33 auto b
= decltype(a
)(); // create a default-constructed second histogram
35 assert(b
!= a
); // b is empty, a is not
39 std::istringstream
is(buf
);
40 boost::archive::text_iarchive
ia(is
);
44 assert(b
== a
); // now b is equal to a