boost::bimap

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值