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. 数据可视化matplotlib、seaborn、pydotplus

    如需转发,请注明出处:小婷儿的python  https://www.cnblogs.com/xxtalhr/p/10486560.html 一.数据可视化 data.mat 链接:https://p ...

  2. android java.lang.NoClassDefFoundError: cn.yw.lib.viewpagerfragment.ViewPagerFragmentActivity

    假如你判断你的项目没有异常,并且该注册的Activity也注册了.那么解决这个问题的方法就是:右击项目->properties->Java Build Path->Order and ...

  3. js求数组的最大值--奇技淫巧和笨方法

    写这篇文章的原因 我目前做的项目很少用到算法,于是这方面的东西自然就有点儿生疏.最近的一次编码中遇到了从数组中获取最大值的需求,当时我不自觉的想到了js的sort()函数,现在想来真是有些“罪过”,当 ...

  4. AngularJs的ng-include的使用与实现

    想在angularjs动态加载一个内容,我们可以使用ng-include来实现. 今天Insus.NET就在ASP.NET MVC环境中,举个例子来演示它的功能. 你可以在一个视图动态加载任一其它视图 ...

  5. 使用awk按照行数切割文件

    最近在做一个事情,需要将一个文本文件按照行数进行切割,然后用了,awk的方法,感觉很好用, 记录一下. 脚本如下: #!/bin/bash ## 文件效果: 根据行数来切割文件 ## 参数1为要切割的 ...

  6. BootStrap学习(2)_下拉菜单&按钮组

    一.下拉菜单 1.基本下拉菜单 如需使用下列菜单,只需要在class .dropdown 内加上下拉菜单即可.下面的实例演示了基本的下拉菜单: <!DOCTYPE html> <ht ...

  7. linux下安装redis组件报错-gcc报错

    报错如图: 1.解决办法    先安装gcc插件.删除redis解压后文件.重新解压

  8. 基于Ping和Telnet/NC的监控脚本案例分析

    案例一:单纯地对某些ip进行ping监控 [root@test opt]# cat /opt/hosts_ip_list 192.168.10.10 192.168.10.11 192.168.10. ...

  9. centos6.8下LNMP (nginx1.8.0+php5.6.10+mysql5.6.12) - 部署手册

    在平时运维工作中,经常需要用到LNMP应用框架.以下对LNMP环境部署记录下: 1)前期准备:为了安装顺利,建议先使用yum安装依赖库[root@opd ~]#yum install -y make ...

  10. Charles使用详解

    前言: Charles是在 Mac 下常用的网络封包截取工具,在做移动开发时,我们为了调试与服务器端的网络通讯协议,常常需要截取网络封包来分析. 一.主界面介绍       二.网页抓包 启动 Cha ...