boost中bimap库使用引例

#include <boost/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <iostream>
#include <string>
#include <map>
#include <utility>
#include <functional>

template <typename map_type>
void print(const map_type& this_map)
{
  for (typename map_type::const_iterator it = this_map.begin(); it!= this_map.end(); ++it)
    {
      std::cout<<"/t"<<it->first<<"-->"<<it->second<<std::endl;      
    }
}

template <typename bimap_type>
void bimap_insert(bimap_type& this_bimap)
{
  this_bimap.insert( typename bimap_type::value_type(1,"first") );
  this_bimap.insert( typename bimap_type::value_type(2,"second") );
  this_bimap.insert( typename bimap_type::value_type(1,"hello,first"));
  this_bimap.insert( typename bimap_type::value_type(2,"hello,second") );
  this_bimap.insert( typename bimap_type::value_type(3,"first") );
  this_bimap.insert( typename bimap_type::value_type(4,"second") );
  this_bimap.insert( typename bimap_type::value_type(4,"second") );
}


int main(int argc, char* argv[])
{
  boost::bimap< boost::bimaps::multiset_of<int>, boost::bimaps::set_of<std::string> > multiset_set;
  boost::bimap< boost::bimaps::multiset_of<int>, boost::bimaps::multiset_of<std::string> > multiset_multiset;
  boost::bimap< boost::bimaps::set_of<int>, boost::bimaps::set_of<std::string> > set_set;
  boost::bimap< boost::bimaps::set_of<int>, boost::bimaps::multiset_of<std::string> > set_multiset;

  std::cout<<"left multiset right set:"<<std::endl;
  bimap_insert(multiset_set);
  std::cout<<"   right view:"<<std::endl;
  print(multiset_set.right);
  std::cout<<"   left view:"<<std::endl;
  print(multiset_set.left);

  std::cout<<std::endl<<"left multiset right multiset:"<<std::endl;
  bimap_insert(multiset_multiset);
  std::cout<<"   right view:"<<std::endl;
  print(multiset_multiset.right);
  std::cout<<"   left view:"<<std::endl;
  print(multiset_multiset.left);

  std::cout<<std::endl<<"left set right set:"<<std::endl;
  bimap_insert(set_set);
  std::cout<<"   right view:"<<std::endl;
  print(set_set.right);
  std::cout<<"   left view:"<<std::endl;
  print(set_set.left);

  std::cout<<std::endl<<"left set right multiset:"<<std::endl;
  bimap_insert(set_multiset);
  std::cout<<"   right view:"<<std::endl;
  print(set_multiset.right);
  std::cout<<"   left view:"<<std::endl;
  print(set_multiset.left);
 
  std::map<int, std::string> my_map;

  my_map.insert(std::make_pair(1,"one"));
  my_map.insert(std::make_pair(1,"yijunjun"));// no effect

  std::cout<<my_map[1]<<std::endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值