]>
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. | |
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 | ||
26 | #include <boost/bimap/bimap.hpp> | |
27 | #include <boost/bimap/support/lambda.hpp> | |
28 | ||
29 | using namespace boost::bimaps; | |
30 | ||
31 | void using_upper_and_lower_bound() | |
32 | { | |
33 | //[ code_tutorial_range_standard_way | |
34 | ||
35 | typedef bimap<int,std::string> bm_type; | |
36 | bm_type bm; | |
37 | ||
38 | // ... | |
39 | ||
40 | bm_type::left_iterator iter_first = bm.left.lower_bound(20); | |
41 | bm_type::left_iterator iter_second = bm.left.upper_bound(50); | |
42 | ||
43 | // range [iter_first,iter_second) contains the elements in [20,50] | |
44 | //] | |
45 | ||
46 | // Subtle changes | |
47 | { | |
48 | //[ code_tutorial_range_standard_way_subtle_changes | |
49 | ||
50 | bm_type::left_iterator iter_first = bm.left.upper_bound(20); | |
51 | bm_type::left_iterator iter_second = bm.left.lower_bound(50); | |
52 | ||
53 | // range [iter_first,iter_second) contains the elements in (20,50) | |
54 | //] | |
55 | } | |
56 | } | |
57 | ||
58 | void using_range() | |
59 | { | |
60 | //[ code_tutorial_range | |
61 | ||
62 | typedef bimap<int,std::string> bm_type; | |
63 | bm_type bm; | |
64 | ||
65 | // ... | |
66 | ||
67 | /*<< `range_type` is a handy typedef equal to `std::pair<iterator,iterator>`. | |
68 | `const_range_type` is provided too, and it is equal to | |
69 | `std::pair<const_iterator,const_iterator>` >>*/ | |
70 | bm_type::left_range_type r; | |
71 | ||
72 | /*<< _key is a Boost.Lambda placeholder. To use it you have to include | |
73 | `<boost/bimap/support/lambda.hpp>` >>*/ | |
74 | r = bm.left.range( 20 <= _key, _key <= 50 ); // [20,50] | |
75 | ||
76 | r = bm.left.range( 20 < _key, _key < 50 ); // (20,50) | |
77 | ||
78 | r = bm.left.range( 20 <= _key, _key < 50 ); // [20,50) | |
79 | //] | |
80 | ||
81 | //[ code_tutorial_range_unbounded | |
82 | ||
83 | r = bm.left.range( 20 <= _key, unbounded ); // [20,inf) | |
84 | ||
85 | r = bm.left.range( unbounded , _key < 50 ); // (-inf,50) | |
86 | ||
87 | /*<< This is equivalent to std::make_pair(s.begin(),s.end()) >>*/ | |
88 | r = bm.left.range( unbounded , unbounded ); // (-inf,inf) | |
89 | //] | |
90 | } | |
91 | ||
92 | int main() | |
93 | { | |
94 | using_upper_and_lower_bound(); | |
95 | using_range(); | |
96 | ||
97 | return 0; | |
98 | } | |
99 | ||
100 |