]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/bimap/example/mi_to_b_path/tagged_bidirectional_map.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)
10 // Boost.Bimap Example
11 //-----------------------------------------------------------------------------
12 // This example shows how to construct a bidirectional map with
13 // multi_index_container.
14 // By a bidirectional map we mean a container of elements of
15 // std::pair<const FromType,const ToType> such that no two elements exists with
16 // the same first or second value (std::map only guarantees uniqueness of the
18 // Fast lookup is provided for both keys. The program features a tiny
19 // Spanish-English dictionary with online query of words in both languages.
21 //[ code_mi_to_b_path_tagged_bidirectional_map
25 #include <boost/bimap/bimap.hpp>
27 using namespace boost::bimaps
;
34 // A dictionary is a bidirectional map from strings to strings
38 tagged
< std::string
,spanish
>, tagged
< std::string
,english
>
42 typedef dictionary::value_type translation
;
48 // Fill up our microdictionary.
49 // first members Spanish, second members English.
51 d
.insert( translation("hola" ,"hello" ));
52 d
.insert( translation("adios","goodbye"));
53 d
.insert( translation("rosa" ,"rose" ));
54 d
.insert( translation("mesa" ,"table" ));
56 std::cout
<< "enter a word" << std::endl
;
58 std::getline(std::cin
,word
);
60 // search the queried word on the from index (Spanish) */
62 dictionary::map_by
<spanish
>::const_iterator it
=
63 d
.by
<spanish
>().find(word
);
65 if( it
!= d
.by
<spanish
>().end() )
67 std::cout
<< word
<< " is said "
68 << it
->get
<english
>() << " in English" << std::endl
;
72 // word not found in Spanish, try our luck in English
74 dictionary::map_by
<english
>::const_iterator it2
=
75 d
.by
<english
>().find(word
);
77 if( it2
!= d
.by
<english
>().end() )
79 std::cout
<< word
<< " is said "
80 << it2
->get
<spanish
>() << " in Spanish" << std::endl
;
84 std::cout
<< "No such word in the dictionary" << std::endl
;