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这篇文章,这里我用自己的语言重新组织,稍作修改和补充,最主要是方便 ...
随机推荐
- 《转载》化繁为简 如何向老婆解释MapReduce?
本文转载自http://server.zol.com.cn/329/3295529.html 昨天,我在Xebia印度办公室发表了一个关于MapReduce的演说.演说进行得很顺利,听众们都能够理解M ...
- rebot的使用
rebot简要使用方法介绍 在介绍rebot前,首先说一下RobotFramework(后称RF)的主要输出文件. 当我们执行完一个RF脚本后,RF会输出3种文件.分别是Output.Log和Re ...
- Linux下安装Scala
Linux下安装Scala和Windows下安装类似,步骤如下: 首先访问下载链接:http://www.scala-lang.org/download/默认这里下载的是Windows版本,这时点击上 ...
- 表现层的设计(一)——常用的模式、Json与DTO
上几篇博文介绍了 业务逻辑层和数据访问层,我认为写博文的作用主要是向业界的读者交流一种思想,点到为止,至于学习架构设计,通过几篇博文是讲不清楚的,还需要[基础]扎实的情况下,[反复]研究[权威]的书籍 ...
- jq获取绝对定位与相对定位的top, left值
jquery 实现方法绝对var X = $('#ID').offset().top; var Y = $('#ID').offset().left; 相对var X = $('#ID').posit ...
- jquery after append appendTo三个函数的区别
jq文档的说明是 1.after函数 定义和用法: after() 方法在被选元素后插入指定的内容. 语法: $(selector).after(content) 实例: <html> & ...
- JavaScript实现字符串的contains函数
JavaScript实现字符串的contains函数 / * * string:原始字符串 * substr:子字符串 * isIgnoreCase:忽略大小写 * / function co ...
- 【leetcode】Maximum Gap(hard)★
Given an unsorted array, find the maximum difference between the successive elements in its sorted f ...
- 【leetcode】Rotate List(middle)
Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...
- 【leetcode】Longest Consecutive Sequence(hard)☆
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...