3 // Copyright (c) 2006-2007 Matias Capeletto
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // VC++ 8.0 warns on usage of certain Standard Library and API functions that
10 // can be cause buffer overruns or other possible security issues if misused.
11 // See http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
12 // But the wording of the warning is misleading and unsettling, there are no
13 // portable alternative functions, and VC++ 8.0's own libraries use the
14 // functions in question. So turn off the warnings.
15 #define _CRT_SECURE_NO_DEPRECATE
16 #define _SCL_SECURE_NO_DEPRECATE
18 // Boost.Bimap Example
19 //-----------------------------------------------------------------------------
21 #include <boost/config.hpp>
27 #include <boost/bimap/bimap.hpp>
29 #include <boost/archive/text_oarchive.hpp>
30 #include <boost/archive/text_iarchive.hpp>
32 using namespace boost::bimaps
;
36 //[ code_bimap_and_boost_serialization
38 typedef bimap
< std::string
, int > bm_type
;
40 // Create a bimap and serialize it to a file
43 bm
.insert( bm_type::value_type("one",1) );
44 bm
.insert( bm_type::value_type("two",2) );
46 std::ofstream
ofs("data");
47 boost::archive::text_oarchive
oa(ofs
);
49 oa
<< const_cast<const bm_type
&>(bm
); /*<
50 We must do a const cast because Boost.Serialization archives
51 only save const objects. Read Boost.Serializartion docs for the
52 rationale behind this decision >*/
54 /*<< We can only serialize iterators if the bimap was serialized first.
55 Note that the const cast is not requiered here because we create
56 our iterators as const. >>*/
57 const bm_type::left_iterator left_iter
= bm
.left
.find("two");
60 const bm_type::right_iterator right_iter
= bm
.right
.find(1);
64 // Load the bimap back
68 std::ifstream
ifs("data", std::ios::binary
);
69 boost::archive::text_iarchive
ia(ifs
);
73 assert( bm
.size() == 2 );
75 bm_type::left_iterator left_iter
;
78 assert( left_iter
->first
== "two" );
80 bm_type::right_iterator right_iter
;
83 assert( right_iter
->first
== 1 );