#include<iostream>#include<string>#include<boost/bimap/bimap.hpp>#include<boost/bimap/list_of.hpp>#include<boost/bimap/unordered_set_of.hpp>structenglish{};structspanish{};intmain(){usingnamespaceboost::bimaps;typedefbimap<unordered_set_of<tagged<std::string,spanish>>,unordered_set_of<tagged<std::string,english>>,list_of_relation>translator;translatortrans;// We have to use `push_back` because the collection of relations is// a `list_of_relation`trans.push_back(translator::value_type("hola","hello"));trans.push_back(translator::value_type("adios","goodbye"));trans.push_back(translator::value_type("rosa","rose"));trans.push_back(translator::value_type("mesa","table"));std::cout<<"enter a word"<<std::endl;std::stringword;std::getline(std::cin,word);// Search the queried word on the from index (Spanish)translator::map_by<spanish>::const_iteratoris=trans.by<spanish>().find(word);if(is!=trans.by<spanish>().end()){std::cout<<word<<" is said "<<is->get<english>()<<" in English"<<std::endl;}else{// Word not found in Spanish, try our luck in Englishtranslator::map_by<english>::const_iteratorie=trans.by<english>().find(word);if(ie!=trans.by<english>().end()){std::cout<<word<<" is said "<<ie->get<spanish>()<<" in Spanish"<<std::endl;}else{// Word not found, show the possible translationsstd::cout<<"No such word in the dictionary"<<std::endl;std::cout<<"These are the possible translations"<<std::endl;for(translator::const_iteratori=trans.begin(),i_end=trans.end();i!=i_end;++i){std::cout<<i->get<spanish>()<<" <---> "<<i->get<english>()<<std::endl;}}}return0;}
Статья Mighty Bimap раздела Chapter 1. Boost.Bimap Examples может быть полезна для разработчиков на c++ и boost.
Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.