boost multi_index_container 基本介绍
来源:互联网 发布:淘宝买眼镜靠谱吗 编辑:程序博客网 时间:2024/05/17 01:16
Boost Multi-index Containers Library定义了multi_index_container模板类,可以从不同的维度建索引、排序和存取。
如上图,容器multi_index_container分别从shape,number和sequenced(默认插入的顺序)三个维度对元素进行管理。
使用如下:
#include <string>#include <iostream>#include <boost/multi_index_container.hpp>#include <boost/multi_index/member.hpp>#include <boost/multi_index/ordered_index.hpp>using namespace boost;using namespace boost::multi_index;using namespace std;struct Employee{ int id; string name; int age; Employee(int id_,std::string name_,int age_):id(id_),name(name_),age(age_){} friend std::ostream& operator<<(std::ostream& os,const Employee& e) { os<<e.id<<" "<<e.name<<" "<<e.age<<std::endl; return os; }};typedef multi_index_container< Employee, indexed_by< ordered_unique<member<Employee, int, &Employee::id> >, ordered_non_unique<member<Employee, string, &Employee::name> >, ordered_non_unique<member<Employee, int, &Employee::age> > >> EmployeeContainer;typedef EmployeeContainer::nth_index<0>::type IdIndex;typedef EmployeeContainer::nth_index<1>::type NameIndex;typedef EmployeeContainer::nth_index<2>::type AgeIndex;int main(){ EmployeeContainer con; con.insert(Employee(0,"Joe",31)); con.insert(Employee(1,"Robert",27)); con.insert(Employee(2,"John",40)); IdIndex& ids = con.get<0>(); copy(ids.begin(),ids.end(), ostream_iterator<Employee>(cout)); cout << endl; NameIndex& names = con.get<1>(); copy(names.begin(), names.end(), ostream_iterator<Employee>(cout)); cout << endl; names.erase(names.begin()); AgeIndex& ages = con.get<2>(); copy(ages.begin(), ages.end(), ostream_iterator<Employee>(cout)); cout << endl; return 0;}
- boost multi_index_container 基本介绍
- Boost multi_index_container
- 关于boost multi_index_container
- Boost组件multi_index_container实例(1)
- Boost组件multi_index_container实例(后续)
- Boost组件multi_index_container实例(续2)
- Boost组件multi_index_container实例(续3)
- Boost组件multi_index_container实例(续4)
- Boost组件multi_index_container实例(续5)
- Boost组件multi_index_container组合查询实例(1)
- boost多个关键字索引multi_index_container
- [HengStar-Boost讲堂]多索引容器multi_index_container实战
- [HengStar-Boost讲堂]多索引容器multi_index_container实战
- Boost组件multi_index_container组合查询实例(续2)
- Boost组件multi_index_container组合查询实例(续3)
- [HengStar-Boost讲堂]多索引容器multi_index_container实战
- [HengStar-Boost讲堂]多索引容器multi_index_container实战
- 多索引容器boost::multi_index_container储存共享智能指针boost::shared_ptr
- 流量监控实战
- eclipse设置字体大小
- 如何查看电脑是32位的(X86)还是64位的(X64),如何知道自己的硬件是否支持64位系统?
- equals详解
- ComputedCSSStyleDeclaration未定义异常
- boost multi_index_container 基本介绍
- 谢谢这一年
- C电子地图
- ABAP TBL隐藏列
- Convert a String In C++ To Upper or Lower Case
- 常用调试命令
- gdb review data
- ABAP TBL鼠标滚动到某行某列
- switch case语句详解---连C++ Primer都会出现的语法错误