1 | // Boost.Bimap |
2 | // |
3 | // Copyright (c) 2006-2007 Matias Capeletto |
4 | // |
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) |
8 | |
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 |
17 | |
18 | // Boost.Bimap Example |
19 | //----------------------------------------------------------------------------- |
20 | |
21 | #include <boost/config.hpp> |
22 | |
23 | #include <string> |
24 | |
25 | #include <boost/assign/list_of.hpp> |
26 | #include <boost/assign/list_inserter.hpp> |
27 | |
28 | #include <boost/bimap/bimap.hpp> |
29 | #include <boost/bimap/multiset_of.hpp> |
30 | #include <boost/bimap/list_of.hpp> |
31 | |
32 | using namespace boost::bimaps; |
33 | using namespace boost; |
34 | |
35 | |
36 | int main() |
37 | { |
38 | //[ code_bimap_and_boost_assign |
39 | |
40 | typedef bimap< multiset_of< int >, list_of< std::string > > bm_type; |
41 | |
42 | // We can use assign::list_of to initialize the container. |
43 | |
44 | bm_type bm = assign::list_of< bm_type::relation > /*< |
45 | Note that `bm_type::relation` has to be used instead of `bm_type::value_type`. |
46 | Contrary to `value_type`, `relation` type stores the elements as non const, a |
47 | requirement of `assign::list_of` >*/ |
48 | ( u: 1, u0: "one" ) |
49 | ( 2, "two" ) |
50 | ( 3, "three" ); |
51 | |
52 | // The left map view is a multiset, again we use insert |
53 | |
54 | assign::insert( c&: bm.left ) |
55 | ( 4, "four" ) |
56 | ( 5, "five" ) |
57 | ( 6, "six" ); |
58 | |
59 | // The right map view is a list so we use push_back here |
60 | // Note the order of the elements in the list! |
61 | |
62 | assign::push_back( c&: bm.right ) |
63 | ( "seven" , 7 ) |
64 | ( "eight" , 8 ); |
65 | |
66 | assign::push_front( c&: bm.right ) |
67 | ( "nine" , 9 ) |
68 | ( "ten" , 10 ) |
69 | ( "eleven" , 11 ); |
70 | |
71 | // Since it is left_based the main view is a multiset, so we use insert |
72 | |
73 | assign::insert( c&: bm ) |
74 | ( 12, "twelve" ) |
75 | ( 13, "thirteen" ); |
76 | //] |
77 | |
78 | return 0; |
79 | } |
80 | |