multi_index_container 多索引容器
multi_index_container是c++ boost库中的一个多索引的容器。因工作中用到了,特来测试试用。
#include "stdafx.h"
#include "test.h" #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 std;
using namespace boost;
using namespace boost::multi_index; struct Book{
int id;
int date;
string name;
string author; Book(int id_,
int date_,
string name_,
string author_)
{
id = id_;
date = date_;
name = name_;
author = author_;
}
}; typedef multi_index_container<
Book,
indexed_by<
ordered_unique<member<Book, int, &Book::id> >,
ordered_non_unique<member<Book, int, &Book::date> >,
ordered_non_unique<member<Book, string, &Book::name> >,
ordered_non_unique<member<Book, string, &Book::author> >
> >BookContainer; typedef BookContainer::nth_index<>::type Id_Index;
typedef BookContainer::nth_index<>::type Date_Index;
typedef BookContainer::nth_index<>::type Name_Index;
typedef BookContainer::nth_index<>::type Author_Index; int _tmain(int argc, _TCHAR* argv[])
{
BookContainer con;
con.insert(Book(, , "math book", "jim"));
con.insert(Book(, , "chinese book", "jam"));
con.insert(Book(, , "english book", "roland"));
con.insert(Book(, , "music book", "rose")); Id_Index& id_idx = con.get<>();
for (auto iter = id_idx.begin(); iter != id_idx.end(); iter++)
{
cout << iter->id << " "
<< iter->date << " "
<< iter->name << " "
<< iter->author << endl;
} cout << endl; Date_Index& date_idx = con.get<>();
for (auto iter = date_idx.begin(); iter != date_idx.end(); iter++)
{
cout << iter->id << " "
<< iter->date << " "
<< iter->name << " "
<< iter->author << endl;
} cout << endl; Name_Index& name_idx = con.get<>();
for (auto iter = name_idx.begin(); iter != name_idx.end(); iter++)
{
cout << iter->id << " "
<< iter->date << " "
<< iter->name << " "
<< iter->author << endl;
} cout << endl; Author_Index& author_idx = con.get<>();
for (auto iter = author_idx.begin(); iter != author_idx.end(); iter++)
{
cout << iter->id << " "
<< iter->date << " "
<< iter->name << " "
<< iter->author << endl;
} getchar();
return ;
}
输出:

可以看到以int型为索引的,输出是按照从小到大来排序的。以string为索引的,是按照字母顺序来输出的。
multi_index_container 多索引容器的更多相关文章
- boost::multi_index 多索引容器
#include "stdafx.h" #include <string> #include <boost/multi_index_container.hpp&g ...
- multi_index_container
转自:https://blog.csdn.net/buptman1/article/details/38657807 multi_index_container: Boost Multi-index ...
- boost multi_index
/** boost 多索引容器的一般使用 这里使用google 的gmock 库来验证对boost 多索引模板的使用,并验证. 这里是手敲的,可能会有一些字符敲错的情况,编译错误的放,修改一下,同时链 ...
- Microsoft开源跨平台的序列化库——Bond
上个月Microsoft开源了Bond,一个跨平台的模式化数据处理框架.Bond支持跨语言的序列化/反序列化,支持强大的泛型机制能够对数据进行有效地处理.该框架在Microsoft公司内部的高扩展服务 ...
- Bjarne Stroustrup对C++程序员的忠告
转自:http://blog.csdn.net/adm_qxx/archive/2007/05/20/1617488.aspx 第1章 致读者 [1] 在编写程序时,你是在为你针对某个问题的解决方 ...
- boost库的安装,使用,介绍,库分类
1)首先去官网下载boost源码安装包:http://www.boost.org/ 选择下载对应的boost源码包.本次下载使用的是 boost_1_60_0.tar.gz (2)解压文件:tar - ...
- Vulkan Tutorial 29 Loading models
操作系统:Windows8.1 显卡:Nivida GTX965M 开发工具:Visual Studio 2017 Introduction 应用程序现在已经可以渲染纹理3D模型,但是 vertice ...
- STL六大组件
1.容器 顺序容器.关联容器 2.算法 各种常用算法,sort.search.copy…… 3.迭代器 用来索引容器中元素,是容器与算法之间的胶合剂 4.仿函数(另名函数对象) 仿函数就是让一个类的使 ...
- OO第13-14次作业总结
目录 面向对象第13-14次作业总结博客 1.设计分析 2.架构总结.测试 3.课程收获和建议 面向对象第13-14次作业总结博客 1.设计分析 这个单元是我做的最差的一个单元.总工程量超过2000行 ...
随机推荐
- Objective-C @executable_path、@loader_path和@rpath
工程配置中,有三个路径和库的加载息息相关: 1.@executable_path 可执行文件的路径,例如/Applications/WeChat.app/Contents/MacOS. 2.@load ...
- EasyUI tab
1.新增tab2.关闭tab3.右键菜单(关闭.关闭所有.关闭其它.关闭右侧.关闭左侧) //双击关闭tab $(document).on("dblclick", ".t ...
- git安装配置
1.git 安装 sudo apt-get install git 2.配置本机git的两个重要信息,user.name和user.email git config --global user.nam ...
- co模块源码学习笔记
// Sorrow.X --- 添加注释,注释纯属个人理解 /** * slice变量 引用 数组的 slice方法 */ var slice = Array.prototype.slice; /** ...
- 如何控制docker的CPU和内存份额
1.内存:docker run -it -m 200M --memory-swap=300M progrium/stress --vm 1 --vm-bytes 500M 刚开始会报错: docker ...
- Android6.0权限大全和权限分类
本文转载至: https://blog.csdn.net/qq_26440221/article/details/53097868 自从出了Android6.0权限管理之后,再也不能像以前那样粘贴复制 ...
- python_第一章
从今天开始,正式开始学习python书籍:python 编程:从入门到实践. 感兴趣的读者可以去网上搜索这本书,适合读者入门,读下来,不会有任何 晦涩难懂的知识. 1.排序: 正排:sort() ...
- [Oracle][Metadata]如何查找与某一个功能相关的数据字典名
当Oracel的一个新功能出来的时候,我们可能不知道所有与此功能关联的数据字典名称,那么如何才能得到这些 meta data 的 meta data 呢? 可以通过 dicitonary 来查看: 例 ...
- 使用Pyspark进行特征工程时的那些坑
以脚本spark_clean_online_action.py.数据集new_sxf_time_count_1781115582.csv为例: 集群节点包括212.216.217.218.需要注意的是 ...
- JS回调函数--简单易懂有实例
版权声明:本文为博主原创文章,转载请注明出处 初学js的时候,被回调函数搞得很晕,现在回过头来总结一下什么是回调函数. 我们先来看看回调的英文定义:A callback is a function t ...