#define _CRT_SECURE_NO_DEPRECATE
#define _SCL_SECURE_NO_DEPRECATE
#include <boost/config.hpp>
#include <iostream>
#include <string>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/list_of.hpp>
#include <boost/bimap/unordered_set_of.hpp>
struct english {};
struct spanish {};
int main()
{
using namespace boost::bimaps;
typedef bimap
<
unordered_set_of< tagged< std::string, spanish > >,
unordered_set_of< tagged< std::string, english > >,
list_of_relation
> translator;
translator trans;
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::string word;
std::getline(std::cin,word);
translator::map_by<spanish>::const_iterator is
= trans.by<spanish>().find(word);
if( is != trans.by<spanish>().end() )
{
std::cout << word << " is said "
<< is->get<english>()
<< " in English" << std::endl;
}
else
{
translator::map_by<english>::const_iterator ie
= trans.by<english>().find(word);
if( ie != trans.by<english>().end() )
{
std::cout << word << " is said "
<< ie->get<spanish>()
<< " in Spanish" << std::endl;
}
else
{
std::cout << "No such word in the dictionary" << std::endl;
std::cout << "These are the possible translations" << std::endl;
for( translator::const_iterator
i = trans.begin(),
i_end = trans.end();
i != i_end ; ++i )
{
std::cout << i->get<spanish>()
<< " <---> "
<< i->get<english>()
<< std::endl;
}
}
}
return 0;
}