Ticket #10740: test_z.cpp

File test_z.cpp, 1.5 KB (added by Robert Ramey, 8 years ago)

altered version of bug.cpp

Line 
1/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2// test_z.cpp
3
4// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
5// Use, modification and distribution is subject to the Boost Software
6// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8
9#include <iostream>
10#include <vector>
11#include <fstream>
12
13#include <boost/serialization/vector.hpp>
14#include <boost/archive/text_oarchive.hpp>
15#include <boost/archive/text_iarchive.hpp>
16
17struct dummy {
18 int m_id;
19 template<class Archive>
20 void serialize(Archive& ar, unsigned int version) {
21 ar & m_id;
22 }
23 dummy() :
24 m_id(0)
25 {}
26 bool operator==(const dummy & rhs){
27 return m_id == rhs.m_id;
28 }
29};
30
31int main() {
32 // Two-level container
33 // This is buggy.
34 std::cout << "Two-level vector:" <<std::endl;
35 std::vector<std::vector<dummy> > l(1, std::vector<dummy>(1));
36 l[0][0].m_id = 42;
37 dummy* pd = &l.back().back();
38 std::cout << pd << std::endl;
39 {
40 std::ofstream ofs("two_level.txt");
41 boost::archive::text_oarchive oa(ofs);
42 oa << l;
43 oa << pd;
44 }
45 dummy* pd1;
46 std::vector<std::vector<dummy> > l1;
47 {
48 std::ifstream ifs("two_level.txt");
49 boost::archive::text_iarchive ia(ifs);
50 ia >> l1;
51 ia >> pd1;
52 }
53 std::cout << pd1 << std::endl;
54 assert(l[0][0] == l1[0][0]);
55 assert(*pd == *pd1);
56
57 return 0;
58}