]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/bimap/example/at_function_examples.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / bimap / example / at_function_examples.cpp
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 #include <iostream>
25 #include <cassert>
26
27 #include <boost/bimap/bimap.hpp>
28 #include <boost/bimap/unordered_set_of.hpp>
29 #include <boost/bimap/list_of.hpp>
30 #include <boost/bimap/multiset_of.hpp>
31
32 using namespace boost::bimaps;
33
34 void first_bimap()
35 {
36 //[ code_at_function_first
37
38 typedef bimap< set_of< std::string >, list_of< int > > bm_type;
39 bm_type bm;
40
41 try
42 {
43 bm.left.at("one") = 1; // throws std::out_of_range
44 }
45 catch( std::out_of_range & e ) {}
46
47 assert( bm.empty() );
48
49 bm.left["one"] = 1; // Ok
50
51 assert( bm.left.at("one") == 1 ); // Ok
52 //]
53 }
54
55 void second_bimap()
56 {
57 //[ code_at_function_second
58
59 typedef bimap< multiset_of<std::string>, unordered_set_of<int> > bm_type;
60 bm_type bm;
61
62 //<-
63 /*
64 //->
65 bm.right[1] = "one"; // compilation error
66 //<-
67 */
68 //->
69
70 bm.right.insert( bm_type::right_value_type(1,"one") );
71
72 assert( bm.right.at(1) == "one" ); // Ok
73
74 try
75 {
76 std::cout << bm.right.at(2); // throws std::out_of_range
77 }
78 catch( std::out_of_range & e ) {}
79
80 //<-
81 /*
82 //->
83 bm.right.at(1) = "1"; // compilation error
84 //<-
85 */
86 //->
87
88 //]
89 }
90
91 int main()
92 {
93 first_bimap();
94 second_bimap();
95 return 0;
96 }
97