]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/bimap/example/repetitions_counter.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>
24 #include <boost/tokenizer.hpp>
26 #include <boost/bimap/bimap.hpp>
27 #include <boost/bimap/unordered_set_of.hpp>
28 #include <boost/bimap/list_of.hpp>
30 using namespace boost::bimaps
;
34 counter
& operator++() { ++c
; return *this; }
35 unsigned int operator++(int) { return c
++; }
36 operator const unsigned int() const { return c
; }
43 //[ code_repetitions_counter
47 unordered_set_of
< std::string
>,
48 list_of
< counter
> /*< `counter` is an integer that is initialized
49 in zero in the constructor >*/
53 typedef boost::tokenizer
<boost::char_separator
<char> > text_tokenizer
;
56 "Relations between data in the STL are represented with maps."
57 "A map is a directed relation, by using it you are representing "
58 "a mapping. In this directed relation, the first type is related to "
59 "the second type but it is not true that the inverse relationship "
60 "holds. This is useful in a lot of situations, but there are some "
61 "relationships that are bidirectional by nature.";
63 // feed the text into the container
65 text_tokenizer
tok(text
,boost::char_separator
<char>(" \t\n.,;:!?'\"-"));
67 for( text_tokenizer::const_iterator it
= tok
.begin(), it_end
= tok
.end();
70 /*<< Because the right collection type is `list_of`, the right data
71 is not used a key and can be modified in the same way as with
76 // list words with counters by order of appearance
77 /*<< When we insert the elements using the left map view, the element
78 is inserted at the end of the list. >>*/
79 for( word_counter::right_const_iterator
80 wit
= wc
.right
.begin(), wit_end
= wc
.right
.end();
82 wit
!= wit_end
; ++wit
)
84 std::cout
<< wit
->second
<< ": " << wit
->first
;