]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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. | |
92f5a8d4 | 11 | // See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx |
7c673cae FG |
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 | #include <iostream> | |
25 | ||
26 | #include <map> | |
27 | #include <boost/bimap/bimap.hpp> | |
28 | ||
29 | using namespace boost::bimaps; | |
30 | ||
31 | //[ code_standard_map_comparison | |
32 | ||
33 | template< class Map, class CompatibleKey, class CompatibleData > | |
34 | void use_it( Map & m, | |
35 | const CompatibleKey & key, | |
36 | const CompatibleData & data ) | |
37 | { | |
38 | typedef typename Map::value_type value_type; | |
39 | typedef typename Map::const_iterator const_iterator; | |
40 | ||
41 | m.insert( value_type(key,data) ); | |
42 | const_iterator iter = m.find(key); | |
43 | if( iter != m.end() ) | |
44 | { | |
45 | assert( iter->first == key ); | |
46 | assert( iter->second == data ); | |
47 | ||
48 | std::cout << iter->first << " --> " << iter->second; | |
49 | } | |
50 | m.erase(key); | |
51 | } | |
52 | ||
53 | int main() | |
54 | { | |
55 | typedef bimap< set_of<std::string>, set_of<int> > bimap_type; | |
56 | bimap_type bm; | |
57 | ||
58 | // Standard map | |
59 | { | |
60 | typedef std::map< std::string, int > map_type; | |
61 | map_type m; | |
62 | ||
63 | use_it( m, "one", 1 ); | |
64 | } | |
65 | ||
66 | // Left map view | |
67 | { | |
68 | typedef bimap_type::left_map map_type; | |
69 | map_type & m = bm.left; | |
70 | ||
71 | use_it( m, "one", 1 ); | |
72 | } | |
73 | ||
74 | // Reverse standard map | |
75 | { | |
76 | typedef std::map< int, std::string > reverse_map_type; | |
77 | reverse_map_type rm; | |
78 | ||
79 | use_it( rm, 1, "one" ); | |
80 | } | |
81 | ||
82 | // Right map view | |
83 | { | |
84 | typedef bimap_type::right_map reverse_map_type; | |
85 | reverse_map_type & rm = bm.right; | |
86 | ||
87 | use_it( rm, 1, "one" ); | |
88 | } | |
89 | ||
90 | return 0; | |
91 | } | |
92 | //] | |
93 |