the usage of data type boost::bimap
#include "stdafx.h"
#include <iostream>
#include <boost/thread.hpp>
#include <boost/atomic.hpp>
#include <boost/range/algorithm/equal.hpp>
#include <boost/algorithm/string.hpp>
#include <string>
#include <boost/assign/std/vector.hpp> // for 'operator+=()'
#include <boost/integer/integer_mask.hpp>
#include <boost/bimap.hpp>
#include <boost/typeof/typeof.hpp>
using namespace std;
using namespace boost::assign; // bring 'operator+=()' into scope
template< class MapType >
void print_map(const MapType & map,
const std::string & separator,
std::ostream & os )
{
typedef typename MapType::const_iterator const_iterator;
for( const_iterator i = map.begin(), iend = map.end(); i != iend; ++i )
{
os << i->first << separator << i->second << std::endl;
}
}
int main()
{
// Soccer World cup
boost::bimap<std::string, int> results;
//Style_1
results.insert( boost::bimap<std::string, int>::value_type("Argentina", 1) );
//Style_2 : left value type
results.left.insert( boost::bimap<std::string, int>::left_value_type("Spain", 2) );
//Style_3 : right value type
results.right.insert( boost::bimap<std::string, int>::right_value_type(3, "Germany") );
//Style_1
results.insert( boost::bimap<std::string, int>::value_type("France", 4) );
std::cout << "The number of countries is " << results.size() << std::endl;
std::cout << "The winner is " << results.right.at(1) << std::endl << std::endl;
std::cout << "Countries names ordered by their final position:" << std::endl;
// results.right works like a std::map< int, std::string >
print_map( results.right, ") ", std::cout );
std::cout
<< std::endl
<< "Countries names ordered alphabetically along with"
"their final position:"
<< std::endl;
// results.left works like a std::map< std::string, int >
print_map( results.left, " ends in position ", std::cout );
cout << endl;
BOOST_AUTO( leftFind , results.left.find("Germany") );
cout << "LeftFind: " << leftFind->first << "," << leftFind->second << endl;
BOOST_AUTO( rightFind , results.right.find(3) );
cout << "RightFind: " << rightFind->first << "," << rightFind->second << endl;
return 0;
}