3 #include <boost/archive/binary_iarchive.hpp>
4 #include <boost/archive/binary_oarchive.hpp>
5 #include <boost/archive/xml_iarchive.hpp>
6 #include <boost/archive/xml_oarchive.hpp>
11 using namespace gtsam;
14 TEST(StdOptionalSerialization, SerializeIntOptional) {
16 std::optional<int> opt(42);
20 boost::archive::text_oarchive oa(
ss);
24 std::optional<int> opt2;
25 boost::archive::text_iarchive ia(
ss);
35 TEST(StdOptionalSerialization, SerializeEmptyOptional) {
37 std::optional<int> opt;
41 boost::archive::text_oarchive oa(
ss);
45 std::optional<int> opt2 = 43;
46 boost::archive::text_iarchive ia(
ss);
59 std::optional<int>
opt;
70 template <
class Archive>
72 ar& BOOST_SERIALIZATION_NVP(
opt);
80 if (q1.
opt.has_value() && q2.
opt.has_value()) {
89 if (
m.opt.has_value()) {
90 std::cout <<
s <<
"opt: " << *
m.opt << std::endl;
92 std::cout <<
s <<
"opt: empty" << std::endl;
99 TEST(StdOptionalSerialization, SerializTestOptionalStruct) {
101 EXPECT(serializationTestHelpers::equalsObj(optStruct));
102 EXPECT(serializationTestHelpers::equalsXML(optStruct));
103 EXPECT(serializationTestHelpers::equalsBinary(optStruct));
107 TEST(StdOptionalSerialization, SerializTestOptionalStructUninitialized) {
109 EXPECT(serializationTestHelpers::equalsObj(optStruct));
110 EXPECT(serializationTestHelpers::equalsXML(optStruct));
111 EXPECT(serializationTestHelpers::equalsBinary(optStruct));
115 TEST(StdOptionalSerialization, SerializTestOptionalStructPointer) {
120 std::stringstream
ss;
121 boost::archive::text_oarchive oa(
ss);
125 std::optional<TestOptionalStruct> opt2;
126 boost::archive::text_iarchive ia(
ss);
135 TEST(StdOptionalSerialization, SerializTestOptionalStructPointerPointer) {
140 std::stringstream
ss;
141 boost::archive::text_oarchive oa(
ss);
145 std::optional<TestOptionalStruct*> opt2;
146 boost::archive::text_iarchive ia(
ss);