C++标准提供了map和multi_map,把key映射到value;
    但是这种映射是单向的,只能是key到value,不能反过来;
    boost.bimap扩展了标准库映射型容器,提供双向映射能力,功能强大;
    bimap提供的映射关系有两个视图:左视图和右视图;
    更多详细用法请参考《Boost程序库完全开发指南》

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 
/* boost_bimap.cpp
    C++标准提供了map和multi_map,把key映射到value;
    但是这种映射是单向的,只能是key到value,不能反过来;
    boost.bimap扩展了标准库映射型容器,提供双向映射能力,功能强大;
    bimap提供的映射关系有两个视图:左视图和右视图;
    更多详细用法请参考《Boost程序库完全开发指南》
*/

#include <iostream>
#include <string>
#include <vector>
#include <cassert>

#include <boost/bimap.hpp>
#include <boost/typeof/typeof.hpp>

using namespace std;
using namespace boost;

template<class T>  
void print_map(T &m)  
{   
    for (BOOST_AUTO(pos, m.begin()); pos!=m.end(); ++pos)  
    {  
        cout << pos->first << "--------" << pos->second << endl;  
    }  
}

int main(void)
{
    bimap<int, string> bm;

bm.left.insert(make_pair(, "Zhang"));
    bm.left.insert(make_pair(, "Wang"));

for(BOOST_AUTO(pos, bm.left.begin()); 
        pos != bm.left.end();
        ++pos)
    {
        cout << "Left[" << pos->first << "]=" << pos->second << endl; 
    }

bm.right.insert(make_pair());
    bm.right.insert(make_pair());

for(BOOST_AUTO(pos, bm.left.begin()); 
        pos != bm.left.end();
        ++pos)
    {
        cout << "Right[" << pos->first << "]=" << pos->second << endl; 
    }

print_map(bm.left);
    print_map(bm.right);

cin.get();
    ;
}

boost容器bimap简单使用的更多相关文章

  1. C++关联容器<map>简单总结

    C++关联容器<map>简单总结 map提供大小可变的关联容器,基于关联键值高效检索元素值.当你处理键值对的数据是,都可以考虑使用map关联容器. 特点: 大小可变的关联容器,基于关联键值 ...

  2. C++线性序列容器<vector>简单总结

    C++线性序列容器<vector>简单总结 vector是一个长度可变的数组,使用的时候无须声明上限,随着元素的增加,Vector的长度会自动增加:Vector类提供额外的方法来增加.删除 ...

  3. boost::bind的简单实现

    前言 在上一篇blog中简单的实现了boost::function,支持带有2个参数的函数/函数指针,函数对象,函数适配器/bind类,以及带有1个参数的成员函数指针. 本文接着来介绍如何实现一个简单 ...

  4. set容器与map容器的简单应用

    set容器中一些函数,取自百度其他大佬已总结好的,如有侵权,请联系删除! set的各成员函数列表如下: c++ stl容器set成员函数:begin()--返回指向第一个元素的迭代器 c++ stl容 ...

  5. Winform MDI窗体容器 权限 简单通讯

    MDI窗体容器 权限  using System; using System.Collections.Generic; using System.ComponentModel; using Syste ...

  6. Unity IOC容器的简单应用(转)

    转自:http://blog.csdn.net/wanzhuan2010/article/details/7763280 Unity是Unity是微软patterns& practices组用 ...

  7. Spring容器的简单实现(IOC原理)

    引言:容器是什么?什么是容器?Spring容器又是啥东西?我给Spring容器一个对象名字,为啥能给我创建一个对象呢? 一.容器是装东西的,就像你家的水缸,你吃饭的碗等等. java中能作为容器的有很 ...

  8. docker简单入门之使用docker容器部署简单的java web开源项目jpress博客程序

    一.在centos7.3上安装docker 前置条件 x86_64-bit 系统 kernel 3.10+ .检查内核版本,返回的值大于3.10即可 [root@node1 ~]# uname -r ...

  9. boost::function的简单实现

    前言 boost::function和boost:bind是一对强大的利器.相信用过的童鞋多少有些体会. 虽然平时在用boost::function,但是用的时候心中总会一些不安,因为不知道它是怎么实 ...

随机推荐

  1. java 内部类、匿名内部类、嵌套类的使用

    我们都知道java的类能够由public.default(缺省.不写)来修饰,分别表示的含义是同意公开訪问以及仅仅同意包内其他类訪问,而同一包内的类一般是为完毕同一个功能而协作.      除此之外, ...

  2. recess----3.Controller如何和View关联

    上一篇我们讲到,Recess框架里面的controller就是一个典型的MVC框架的controller,它负责处理从浏览器(或其它客户端)过来的request,然后调用引用model里面的方法来进行 ...

  3. Python/MOOC /翻Wall和互联网编程的那些事

    Python MOOC 翻Wall和互联网编程的那些事 声明: 1)本报告由博客园bitpeach撰写,版权所有,免费转载,请注明出处,并请勿作商业用途. 2)若本文档内有侵权文字或图片等内容,请联系 ...

  4. hibernate 联合主键

      xml方式处理联合主键:   以有两个主键:id和name的student表为例. 先创建个主键类:   package com.bjsxt.hibernate; //黑色为必写项 public ...

  5. python处理xls、xlsx格式excle

    一.windows下读取xls格式文件,所需模块xlrd.xlw 1.下载安装包 xlrd地址:https://pypi.org/project/xlrd/#files xlwt地址:https:// ...

  6. 理解Linux系统中的load average

    理解Linux系统中的load average(图文版) 博客分类: Linux linux load nagios  一.什么是load average? linux系统中的Load对当前CPU工作 ...

  7. Python sklearn 分类效果评估

    https://blog.csdn.net/sinat_26917383/article/details/75199996

  8. css - 当文本内容长度超出屏幕宽度时,以省略号代替

    <style> .ellipsis{ text-overflow: ellipsis; overflow: hidden; white-space: nowrap; } </styl ...

  9. linux下/etc/hosts 和hostname文件的区别

    很过人一提到更改hostname首先就想到修改/etc/hosts文件,认为hostname的配置文件就是/etc/hosts.其实不是的. hosts文件的作用相当如DNS,提供IP地址到hostn ...

  10. Xilinx资源优化问题

    资源优化问题:Xilinx ise 出现资源不够的问题(ERROR:Cpld:868 - Cannot fit the design into any of the specified devices ...