boost之bimap(2)
来源:互联网 发布:java bind 参数 编辑:程序博客网 时间:2024/05/17 22:30
bimap
#include <iostream>#include <boost/assign.hpp>#include <boost/typeof/typeof.hpp>#include <boost/bimap.hpp>#include <boost/bimap/list_of.hpp>#include <boost/bimap/unordered_multiset_of.hpp>#include <boost/bimap/unordered_set_of.hpp>#include <boost/bimap/vector_of.hpp>#include <boost/bimap/set_of.hpp>#include <boost/bimap/multiset_of.hpp>#include <boost/bimap/unconstrained_set_of.hpp>#include <algorithm>using namespace std;using namespace boost;using namespace boost::bimaps;/////辅助函数template <typename T>void print_map(T &m){ for (BOOST_AUTO(pos, m.begin()); pos != m.end(); ++pos) { cout << pos->left << "------" << pos->right << endl; }}/////辅助函数template <typename T>void print_map1(T &m){ for (BOOST_AUTO(pos, m.begin()); pos != m.end(); ++pos) { cout << pos->first << "------" << pos->second << endl; }}int main(){ //////无序多值的bimap,左值和右值可以插入任意的可重复的值 bimap<unordered_multiset_of<int>, unordered_multiset_of<string>>bm; bm.left.insert(make_pair(1,"111")); bm.left.insert(make_pair(2,"222")); bm.left.insert(make_pair(3,"333")); bm.right.insert(make_pair("4444",4)); bm.right.insert(make_pair("5555",5)); bm.right.insert(make_pair("4444",6)); bm.right.insert(make_pair("7777", 3)); print_map(bm); //////是错的 //for (BOOST_AUTO(pos, bm.begin()); pos != bm.end(); ++pos) //{ // cout << pos->first << "-" << pos->second << endl; //} bimap<set_of<int>, vector_of<string>>bm1; bm1.left.insert(make_pair(1,"1111")); bm1.left[2] = "2222"; //bm1.left.at(3) = "3333"; print_map(bm1); //////是对的 /*for (BOOST_AUTO(pos, bm1.begin()); pos != bm1.end();++pos) { cout << pos->left <<"---"<< pos->right << endl; }*/ //////使用标签类型,避免使用left和right using namespace boost::bimaps; bimap<tagged<int,struct id>,tagged<string,struct name>> bm2; bm2.by<id>().insert(make_pair(1,"lijiajia")); bm2.by<id>().insert(make_pair(2,"caoyanyan")); bm2.by<name>().insert(make_pair("weiyimeng",3)); bm2.by<name>().insert(make_pair("hahahha",4)); print_map1(bm2.by<name>()); /////////使用assign //typedef bimap<multiset_of<int>, vector_of<string>> bm_t; //bm_t bm3 = assign::list_of(bm_t::relation)(1,"1111")(2,"2222"); //insert(bm3.left)(3,"3333")(4,"4444"); //push_back(bm3.right)("5555",5)("6666",6); return 0;}
0 0
- boost之bimap(2)
- boost之bimap(1)
- boost之bimap(3)
- Boost::bimap
- boost::bimap
- boost::bimap详解
- boost bimap简介
- boost bimap 学习笔记
- boost bimap 学习笔记
- Boost::bimap的简单使用
- Guava学习之BiMap
- guava之BiMap
- Guava使用之BiMap
- boost中bimap库使用引例
- 双向映射boost::bimap的使用
- bimap OOM(2)
- BiMap
- BiMap
- Xen虚拟化基础篇
- Redis学习资源
- 66. Plus One
- HTML 事件属性
- 资源网站收集
- boost之bimap(2)
- HTML5 <canvas> 参考手册
- eclipse上开发j2me的错误提示怎么看
- 請問全局BEAN應該怎麼實現
- 杭电OJ题目分类大全
- HTML 音频/视频 DOM 参考手册
- 监控设备-镜头焦距选择技巧!
- eclipse求助!!!
- TML 元素和有效 DOCTYPES