@@ -55,6 +55,38 @@ std::ostream& operator<<(std::ostream& os, OneLA const & s)
55
55
return os;
56
56
}
57
57
58
+ struct OneLAVersioned
59
+ {
60
+ OneLAVersioned ( int xx ) : x( xx ), v() {}
61
+ OneLAVersioned ( int xx, int vv ) : x( xx ), v( vv ) {}
62
+
63
+ int x;
64
+ std::uint32_t v;
65
+
66
+ template <class Archive >
67
+ void serialize ( Archive & ar, const std::uint32_t version )
68
+ { ar ( x ); v = version; }
69
+
70
+ template <class Archive >
71
+ static void load_and_construct ( Archive & ar, cereal::construct<OneLAVersioned> & construct, const std::uint32_t version )
72
+ {
73
+ int xx;
74
+ ar ( xx );
75
+ construct ( xx, version );
76
+ }
77
+
78
+ bool operator ==( OneLAVersioned const & other ) const
79
+ { return x == other.x ; }
80
+ };
81
+
82
+ std::ostream& operator <<(std::ostream& os, OneLAVersioned const & s)
83
+ {
84
+ os << " [" << s.x << " ]" ;
85
+ return os;
86
+ }
87
+
88
+ CEREAL_CLASS_VERSION ( OneLAVersioned, 13 )
89
+
58
90
struct TwoLA
59
91
{
60
92
TwoLA ( int xx ) : x ( xx ) {}
@@ -90,6 +122,45 @@ namespace cereal
90
122
};
91
123
}
92
124
125
+ struct TwoLAVersioned
126
+ {
127
+ TwoLAVersioned ( int xx ) : x( xx ), v() {}
128
+ TwoLAVersioned ( int xx, int vv ) : x( xx ), v( vv ) {}
129
+
130
+ int x;
131
+ std::uint32_t v;
132
+
133
+ template <class Archive >
134
+ void serialize ( Archive & ar, const std::uint32_t version )
135
+ { ar ( x ); v = version; }
136
+
137
+ bool operator ==( TwoLAVersioned const & other ) const
138
+ { return x == other.x ; }
139
+ };
140
+
141
+ std::ostream& operator <<(std::ostream& os, TwoLAVersioned const & s)
142
+ {
143
+ os << " [" << s.x << " ]" ;
144
+ return os;
145
+ }
146
+
147
+ namespace cereal
148
+ {
149
+ template <>
150
+ struct LoadAndConstruct <TwoLAVersioned>
151
+ {
152
+ template <class Archive >
153
+ static void load_and_construct ( Archive & ar, cereal::construct<TwoLAVersioned> & construct, const std::uint32_t version )
154
+ {
155
+ int xx;
156
+ ar ( xx );
157
+ construct ( xx, version );
158
+ }
159
+ };
160
+ }
161
+
162
+ CEREAL_CLASS_VERSION ( TwoLAVersioned, 1 )
163
+
93
164
struct ThreeLA : std::enable_shared_from_this<ThreeLA>
94
165
{
95
166
ThreeLA ( int xx ) : x ( xx ) {}
@@ -131,6 +202,8 @@ void test_memory_load_construct()
131
202
std::unique_ptr<OneLA> o_unique1 ( new OneLA ( random_value<int >(gen) ) );
132
203
std::unique_ptr<TwoLA> o_unique2 ( new TwoLA ( random_value<int >(gen) ) );
133
204
auto o_shared3 = std::make_shared<ThreeLA>( random_value<int >(gen) );
205
+ auto o_shared1v = std::make_shared<OneLAVersioned>( random_value<int >(gen) );
206
+ auto o_shared2v = std::make_shared<TwoLAVersioned>( random_value<int >(gen) );
134
207
135
208
std::ostringstream os;
136
209
{
@@ -141,6 +214,8 @@ void test_memory_load_construct()
141
214
oar ( o_unique1 );
142
215
oar ( o_unique2 );
143
216
oar ( o_shared3 );
217
+ oar ( o_shared1v );
218
+ oar ( o_shared2v );
144
219
}
145
220
146
221
o_shared3->shared_from_this (); // tests github issue #68
@@ -150,6 +225,8 @@ void test_memory_load_construct()
150
225
decltype (o_unique1) i_unique1;
151
226
decltype (o_unique2) i_unique2;
152
227
decltype (o_shared3) i_shared3;
228
+ decltype (o_shared1v) i_shared1v;
229
+ decltype (o_shared2v) i_shared2v;
153
230
154
231
std::istringstream is (os.str ());
155
232
{
@@ -160,13 +237,19 @@ void test_memory_load_construct()
160
237
iar ( i_unique1 );
161
238
iar ( i_unique2 );
162
239
iar ( i_shared3 );
240
+ iar ( i_shared1v );
241
+ iar ( i_shared2v );
163
242
}
164
243
165
244
BOOST_CHECK_EQUAL ( *o_shared1, *i_shared1 );
166
245
BOOST_CHECK_EQUAL ( *o_shared2, *i_shared2 );
167
246
BOOST_CHECK_EQUAL ( *o_unique1, *i_unique1 );
168
247
BOOST_CHECK_EQUAL ( *o_unique2, *i_unique2 );
169
248
BOOST_CHECK_EQUAL ( *o_shared3, *i_shared3 );
249
+ BOOST_CHECK_EQUAL ( *o_shared1v, *i_shared1v );
250
+ BOOST_CHECK_EQUAL (i_shared1v->v , 13u );
251
+ BOOST_CHECK_EQUAL ( *o_shared2v, *i_shared2v );
252
+ BOOST_CHECK_EQUAL (i_shared2v->v , 1u );
170
253
171
254
auto i_shared3_2 = i_shared3->shared_from_this ();
172
255
BOOST_CHECK_EQUAL ( *o_shared3, *i_shared3_2 );
0 commit comments