]>
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 | ||
25 | #include <boost/bimap/bimap.hpp> | |
26 | ||
27 | #include <boost/xpressive/xpressive.hpp> | |
28 | #include <boost/xpressive/regex_actions.hpp> | |
29 | ||
30 | using namespace boost::bimaps; | |
31 | using namespace boost::xpressive; | |
32 | namespace xp = boost::xpressive; | |
33 | ||
34 | int main() | |
35 | { | |
36 | //[ code_bimap_and_boost_xpressive | |
37 | ||
38 | typedef bimap< std::string, int > bm_type; | |
39 | bm_type bm; | |
40 | ||
41 | std::string rel_str("one <--> 1 two <--> 2 three <--> 3"); | |
42 | ||
43 | sregex rel = ( (s1= +_w) >> " <--> " >> (s2= +_d) ) | |
44 | [ | |
45 | xp::ref(bm)->*insert( xp::construct<bm_type::value_type>(s1, as<int>(s2)) ) | |
46 | ]; | |
47 | ||
48 | sregex relations = rel >> *(+_s >> rel); | |
49 | ||
50 | regex_match(rel_str, relations); | |
51 | ||
52 | assert( bm.size() == 3 ); | |
53 | //] | |
54 | ||
55 | return 0; | |
56 | } | |
57 |