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 多索引容器的更多相关文章

  1. boost::multi_index 多索引容器

    #include "stdafx.h" #include <string> #include <boost/multi_index_container.hpp&g ...

  2. multi_index_container

    转自:https://blog.csdn.net/buptman1/article/details/38657807 multi_index_container: Boost Multi-index ...

  3. boost multi_index

    /** boost 多索引容器的一般使用 这里使用google 的gmock 库来验证对boost 多索引模板的使用,并验证. 这里是手敲的,可能会有一些字符敲错的情况,编译错误的放,修改一下,同时链 ...

  4. Microsoft开源跨平台的序列化库——Bond

    上个月Microsoft开源了Bond,一个跨平台的模式化数据处理框架.Bond支持跨语言的序列化/反序列化,支持强大的泛型机制能够对数据进行有效地处理.该框架在Microsoft公司内部的高扩展服务 ...

  5. Bjarne Stroustrup对C++程序员的忠告

    转自:http://blog.csdn.net/adm_qxx/archive/2007/05/20/1617488.aspx  第1章 致读者  [1] 在编写程序时,你是在为你针对某个问题的解决方 ...

  6. boost库的安装,使用,介绍,库分类

    1)首先去官网下载boost源码安装包:http://www.boost.org/ 选择下载对应的boost源码包.本次下载使用的是 boost_1_60_0.tar.gz (2)解压文件:tar - ...

  7. Vulkan Tutorial 29 Loading models

    操作系统:Windows8.1 显卡:Nivida GTX965M 开发工具:Visual Studio 2017 Introduction 应用程序现在已经可以渲染纹理3D模型,但是 vertice ...

  8. STL六大组件

    1.容器 顺序容器.关联容器 2.算法 各种常用算法,sort.search.copy…… 3.迭代器 用来索引容器中元素,是容器与算法之间的胶合剂 4.仿函数(另名函数对象) 仿函数就是让一个类的使 ...

  9. OO第13-14次作业总结

    目录 面向对象第13-14次作业总结博客 1.设计分析 2.架构总结.测试 3.课程收获和建议 面向对象第13-14次作业总结博客 1.设计分析 这个单元是我做的最差的一个单元.总工程量超过2000行 ...

随机推荐

  1. Omi框架学习之旅 - 之开篇扯蛋

    说实话, 我也不知道Omi是干啥的, 只因此框架是alloyTeam出的, dntzhang写的, 也有其他腾讯大神参与了, 还有一些其他贡献者, 以上我也不太清楚, 当我胡说八嘎. 因其写法有人说好 ...

  2. Zephyr的Shell

    1 前言 通过Shell可以跟子系统打交道,子系统也可以提供很多接口供外部设置和读取信息. 下面就Shell的Kconfig配置.Shell的使用以及如何新建一个Shell命令展开. 可以说Shell ...

  3. 介绍一个axios调试好用的工具:axios-mock-adapter

    上一篇文章中写到用promise时应注意的问题,这一篇文章继续介绍一个可以和axios库配合的好工具: axios-mock-adapter.axios-mock-adapter可以用来拦截http请 ...

  4. BZOJ4883 棋盘上的守卫 基环树、Kruskal

    题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=4883 题意:给出一个$N \times M$的棋盘,每个格子有权值.你需要每一行选中一 ...

  5. Luogu P2602 [ZJOI2010]数字计数

    这算是一道数位DP的入门题了吧虽然对于我来说还是有点烦 经典起手式不讲了吧,\(ans(a,b)\to ans(1,b)-ans(1,a-1)\) 我们首先预处理一个东西,用\(f_i\)表示有\(i ...

  6. 一文详解如何用 TensorFlow 实现基于 LSTM 的文本分类(附源码)

    雷锋网按:本文作者陆池,原文载于作者个人博客,雷锋网已获授权. 引言 学习一段时间的tensor flow之后,想找个项目试试手,然后想起了之前在看Theano教程中的一个文本分类的实例,这个星期就用 ...

  7. Codeforces 999D Equalize the Remainders (set使用)

    题目连接:Equalize the Remainders 题意:n个数字,对m取余有m种情况,使得每种情况的个数都为n/m个(保证n%m=0),最少需要操作多少次? 每次操作可以把某个数字+1.输出最 ...

  8. 来不及说什么了,Python 运维开发剁手价仅剩最后 2 天

    51reboot 运维开发又双叒叕的搞活动了—— Python 运维开发 18 天训练营课程, 剁手价1299 最后2天 上课方式:网络直播/面授(仅限北京) DAY1 - DAY4 Python3 ...

  9. Matlab入门笔记(1)

    1.简单练习题: cos(((1+2+3+4+5)^3/5)^0.5) sin(pi^0.5)+log(tan(1)) 2^(3.5*1.7) exp(sin(10)) 2.实数,复数,行向量,列向量 ...

  10. B. Heaters Div3

    链接 [http://codeforces.com/contest/1066/problem/B] 分析 具体看代码,贪就完事了 代码 #include<bits/stdc++.h> us ...