Boost练习程序(multi_index_container)
代码来自:http://blog.csdn.net/whuqin/article/details/8482547
该容器能实现多列索引,挺好。
- #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_,string name_,int age_):id(id_),name(name_),age(age_){}
- friend ostream& operator<<(ostream& os,const Employee& e)
- {
- os<<e.id<<" "<<e.name<<" "<<e.age<<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<>::type IdIndex;
- typedef EmployeeContainer::nth_index<>::type NameIndex;
- typedef EmployeeContainer::nth_index<>::type AgeIndex;
- int main(){
- EmployeeContainer con;
- con.insert(Employee(,"Joe",));
- con.insert(Employee(,"Robert",));
- con.insert(Employee(,"John",));
- IdIndex& ids = con.get<>();
- copy(ids.begin(),ids.end(), ostream_iterator<Employee>(cout));
- cout << endl;
- NameIndex& names = con.get<>();
- copy(names.begin(), names.end(), ostream_iterator<Employee>(cout));
- cout << endl;
- // names.erase(names.begin());
- AgeIndex& ages = con.get<>();
- copy(ages.begin(), ages.end(), ostream_iterator<Employee>(cout));
- cout << endl;
- return ;
- }
Boost练习程序(multi_index_container)的更多相关文章
- VS2013第一个应用boost的程序
下载boost binary https://sourceforge.net/projects/boost/files/boost-binaries/1.67.0_b1/ 由于我用的是Windows1 ...
- 新手,Visual Studio 2015 配置Boost库,如何编译和选择,遇到无法打开文件“libboost_thread-vc140-mt-gd-1_63.lib“的解决办法
1,到官网下载最新的boost,www.boost.org 这里我下载的1-63版本. 2,安装,解压后运行bootstrap.bat文件.稍等一小会就OK. 3,编译boost库.注意一定要使用VS ...
- Boost.Python简介
Boost.Python简单概括:是Boost库的一部分:用来在C++代码中调用python代码以及在Python代码中调用C++代码,并且避免用户直接操作指针. 以下内容搬运自:https://wi ...
- windows下用vs2008和boost结合编译程序
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://co63oc.blog.51cto.com/904636/504469 win ...
- Boost程序库完全开发指南——深入C++“准”标准库(第3版)
内容简介 · · · · · · Boost 是一个功能强大.构造精巧.跨平台.开源并且完全免费的C++程序库,有着“C++‘准’标准库”的美誉. Boost 由C++标准委员会部分成员所设立的Bo ...
- boost库的安装,使用,介绍,库分类
1)首先去官网下载boost源码安装包:http://www.boost.org/ 选择下载对应的boost源码包.本次下载使用的是 boost_1_60_0.tar.gz (2)解压文件:tar - ...
- Boost 和 Boost.Build 的设置
问题: 安装编译完 Boost 后,如果不设置 BOOST_ROOT 和 BOOST_BUILD_PATH 则可能导致使用 bjam 时定位到 Boost 默认的路径 /usr/share/boost ...
- 新手,Visual Studio 2013 配置Boost库,如何编译和选择
QuantLib installation in VC++ 2010 and later 参考:http://quantlib.org/install/vc10.shtml 1,到官网下载最新的boo ...
- 【视频开发】【计算机视觉】doppia编译之二:boost安装
编译安装boost库的方法大部分都是来自http://www.linuxidc.com/Linux/2013-07/87573.htm这篇文章,这里我用自己的语言重新组织,稍作修改和补充,最主要是方便 ...
随机推荐
- [转载]能不能同时用static和const修饰类的成员函数?
题目(一):我们可以用static修饰一个类的成员函数,也可以用const修饰类的成员函数(写在函数的最后表示不能修改成员变量,不是指写在前面表示返回值为常量).请问:能不能同时用static和con ...
- pip 安装命令
pip官网文档 https://pip.pypa.io/en/latest/reference/pip.html 若没有将c:\Python27\Scripts加入到path环境变量,可以在c:\Py ...
- 《Java语言程序设计》上机实验
实验一 Java环境演练 [目的] ①安装并配置Java运行开发环境: ②掌握开发Java应用程序的3个步骤:编写源文件.编译源文件和运行应用程序: ③学习同时编译多个Java源文件. [内容 ...
- 为Linux服务器设置静态IP的方法
这里以CentOS 7系列为例设置静态IP,原来RedHat系列的Linux发行版可以通过setup工具方便的设置静态IP,但是在版本7之后setup工具的功能就逐渐减弱了,所以这时候采用修改配置文件 ...
- Linux基础命令总结
1.pwd 查看当前工作目录 2.ls [目录] 列出指定目录下的所有文件,使用 ls -l 或者 ll 列出文件详细列表包括权限.大小等文件默认大小以字节B为单位,目录大小为4096B ls - ...
- 1.SpringMVC的简介和环境搭建
SpringMVC的简介: SpringMVC 和 Struts一样是一个MVC框架,和Spring无缝连接,和struts2类似, Spring MVC属于SpringFrameWork的后续产品, ...
- C#在类中用调用Form的方法
class 你的类 { private Form1 frm; //构造函数 public 你的类( Form1 form) { frm = form; } //调用form方法 private voi ...
- ajax传值方式为数组
js: function responseJson1(){ var array=[1001,1002]; var str=""; //获取table对象 ...
- July 4th, Week 28th Monday, 2016
Goals determine what you are going to be. 你的目标决定你将成为怎样的人. What are your goals? What kind of people y ...
- CABasicAnimation 按home键后台之后,再切回来动画就停止了
解决方法: 1. CABasicAnimation *thisAnimation = [CABasicAnimtaion animationWithKeyPath:@"transform.r ...