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行 ...
随机推荐
- ubuntu系统的谷歌浏览器的安装
Ubuntu 系统通过一下四步能安装谷歌浏览器 1. sudo wget http://www.linuxidc.com/files/repo/google-chrome.list -P /etc/a ...
- svn 从文件上次修改以来没有任何文件修改或加入。
现象:代码已经被修改过了,但是再往svn上提交代码时仍然提示: 从文件上次修改以来没有任何文件修改或加入. 解决办法: 1.找打存放代码的文件夹,右键——TortoiseSVN——clean up(清 ...
- Java中try catch finally语句中含有return语句的执行情况(总结版)
在这里看到了try >但有一点是可以肯定的,finally块中的内容会先于try中的return语句执行,如果finall语句块中也有return语句的话,那么直接从finally中返回了,这也 ...
- Tensorflow-hub[例子解析1]
0. 引言 Tensorflow于1.7之后推出了tensorflow hub,其是一个适合于迁移学习的部分,主要通过将tensorflow的训练好的模型进行模块划分,并可以再次加以利用.不过介于推出 ...
- java中使用jxl读取excel中的数据
package bboss; import java.io.File; import java.io.FileInputStream; import java.io.IOException; impo ...
- CF888G Xor-MST 生成树、分治、Trie树合并
传送门 第一次接触到Boruvka求最小生成树 它的原版本是:初始每一个点构成一个连通块,每一次找到每一个连通块到其他的连通块权值最短的边,然后合并这两个连通块.因为每一次连通块个数至少减半,所以复杂 ...
- Luogu4774 NOI2018 屠龙勇士 ExCRT
传送门 原来NOI也会出裸题啊-- 用multiset求出对付每一个BOSS使用的武器威力\(ATK_i\),可以得到\(m\)个式子\(ATK_ix \equiv a_i \mod p_i\) 看起 ...
- .NET Core 3.0 跟踪
Preview1: https://blogs.msdn.microsoft.com/dotnet/2018/12/04/announcing-net-core-3-preview-1-and-ope ...
- 多线程-synchronized、lock
1.什么时候会出现线程安全问题? 在多线程编程中,可能出现多个线程同时访问同一个资源,可以是:变量.对象.文件.数据库表等.此时就存在一个问题: 每个线程执行过程是不可控的,可能导致最终结果与实际期望 ...
- css实现按钮固定在底部
实现类似如下图的功能: 采用如下的样式来控制: