博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Boost练习程序(multi_index_container)
阅读量:6905 次
发布时间:2019-06-27

本文共 1219 字,大约阅读时间需要 4 分钟。

代码来自:http://blog.csdn.net/whuqin/article/details/8482547

该容器能实现多列索引,挺好。

#include 
#include
#include
#include
#include
using namespace boost;using namespace boost::multi_index;using namespace std;struct Employee{ int id; string name; int age; Employee(int id_,string name_,int age_):id(id_),name(name_),age(age_){} friend ostream& operator<<(ostream& os,const Employee& e) { os<
<<" "<
<<" "<
<
>,ordered_non_unique
>,ordered_non_unique
>>> 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
(cout)); cout << endl; NameIndex& names = con.get<1>(); copy(names.begin(), names.end(), ostream_iterator
(cout)); cout << endl; // names.erase(names.begin()); AgeIndex& ages = con.get<2>(); copy(ages.begin(), ages.end(), ostream_iterator
(cout)); cout << endl; return 0;}

 

你可能感兴趣的文章
React Render props
查看>>
自动类型转换
查看>>
C# winfrom 当前程序内存读取和控制
查看>>
电话号码分身
查看>>
计算机专业术语
查看>>
Leetcode-探索 | 移动零
查看>>
DBI 数据库模块剖析:Perl DBI 数据库通讯模块规范,工作原理和实例
查看>>
Tesseract+opencv+VS+win实现OCR
查看>>
android在activity中锁屏解锁后重走OnCreate的问题的解决办法
查看>>
[学习笔记]博弈论
查看>>
python os sys模块(二)
查看>>
一次linux启动故障记录
查看>>
linux 3.10内核 xfs的一次io异常导致的hung crash
查看>>
Castle ActiveRecord学习笔记(转)
查看>>
springboot+mybatis环境的坑和sql语句简化技巧
查看>>
Keil C编译器的变量存储分配
查看>>
非常不错的js 屏蔽类加验证类
查看>>
Innodb间隙锁,细节讲解(转)
查看>>
Apache安装
查看>>
C语言练习题库----数组
查看>>