]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/bimap/example/tutorial_info_hook.cpp
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>
26 #include <boost/bimap/bimap.hpp>
27 #include <boost/bimap/multiset_of.hpp>
29 using namespace boost::bimaps
;
32 void tutorial_about_info_hook()
34 //[ code_tutorial_info_hook_first
38 multiset_of
< std::string
>, // author
39 set_of
< std::string
>, // title
41 with_info
< std::string
> // abstract
44 typedef bm_type::value_type book
;
50 book( "Bjarne Stroustrup" , "The C++ Programming Language",
52 "For C++ old-timers, the first edition of this book is"
53 "the one that started it all—the font of our knowledge." )
57 // Print the author of the bible
58 std::cout
<< bm
.right
.at("The C++ Programming Language");
60 // Print the abstract of this book
61 bm_type::left_iterator i
= bm
.left
.find("Bjarne Stroustrup");
65 // Contrary to the two key types, the information will be mutable
68 //[ code_tutorial_info_hook_mutable
70 i
->info
+= "More details about this book";
73 // A new function is included in unique map views: info_at(key), that
74 // mimics the standard at(key) function but returned the associated
75 // information instead of the data.
77 //[ code_tutorial_info_hook_info_at
79 // Print the new abstract
80 std::cout
<< bm
.right
.info_at("The C++ Programming Language");
88 void tutorial_about_tagged_info_hook()
90 //[ code_tutorial_info_hook_tagged_info
94 multiset_of
< tagged
< std::string
, author
> >,
95 set_of
< tagged
< std::string
, title
> >,
97 with_info
< tagged
< std::string
, abstract
> >
100 typedef bm_type::value_type book
;
106 book( "Bjarne Stroustrup" , "The C++ Programming Language",
108 "For C++ old-timers, the first edition of this book is"
109 "the one that started it all—the font of our knowledge." )
112 // Print the author of the bible
113 std::cout
<< bm
.by
<title
>().at("The C++ Programming Language");
115 // Print the abstract of this book
116 bm_type::map_by
<author
>::iterator i
= bm
.by
<author
>().find("Bjarne Stroustrup");
117 std::cout
<< i
->get
<abstract
>();
119 // Contrary to the two key types, the information will be mutable
122 i
->get
<abstract
>() += "More details about this book";
124 // Print the new abstract
125 std::cout
<< bm
.by
<title
>().info_at("The C++ Programming Language");
130 void bimap_without_an_info_hook()
132 //[ code_tutorial_info_hook_nothing
136 multiset_of
< std::string
>, // author
137 set_of
< std::string
> // title
140 typedef bm_type::value_type book
;
144 bm
.insert( book( "Bjarne Stroustrup" , "The C++ Programming Language" ) );
145 bm
.insert( book( "Scott Meyers" , "Effective C++" ) );
146 bm
.insert( book( "Andrei Alexandrescu" , "Modern C++ Design" ) );
148 // Print the author of Modern C++
149 std::cout
<< bm
.right
.at( "Modern C++ Design" );
156 tutorial_about_info_hook();
157 tutorial_about_tagged_info_hook();
158 bimap_without_an_info_hook();