#include "stdafx.h"
#include <string>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/composite_key.hpp>
#include <boost/multi_index/ordered_index.hpp>
using namespace std;
using namespace boost;
/*
定义一个MutiStruct
key : 1. objectID
2. strName value: 对象指针STNodePtr
*/
struct MutiStruct
{
int   objectID;//唯一
string strName;//唯一 STNodePtr ptrNode;//设备对象指针
}; /*
定义容器,索引
*/
using MutiContainer = boost::multi_index::multi_index_container <
MutiStruct,
boost::multi_index::indexed_by <
boost::multi_index::ordered_unique<boost::multi_index::member<MutiStruct, int, &MutiStruct::objectID>>,
boost::multi_index::ordered_unique<boost::multi_index::member<MutiStruct, string, &MutiStruct::strName>>
>
>; /*
有多少个key,就定义多少个枚举,
0:表示以第一个索引作为key。
1:表示以第二个索引作为key。
*/
enum
{
KEY_1_VIEW = ,
KEY_2_VIEW =
};
using MI_OBJ_IDX = MutiContainer::nth_index<KEY_1_VIEW>::type;
using MI_NAME_IDX = MutiContainer::nth_index<KEY_2_VIEW>::type;
/*插入数据到容器*/
MutiContainer Conter; MutiStruct mi;
mi.objectID = ;
mi.strName = "nihao"; std::pair<MutiContainer::iterator, bool> p = Conter.insert(mi);
if (!p.second)
{
printf("insert fail \n");
}

boost::multi_index 多索引容器的更多相关文章

  1. boost multi_index

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

  2. 用 boost::multi_index 管理玩家

    用 boost::multi_index 管理玩家(金庆的专栏)网游服务器上的玩家集合需要多种索引:如用ID查找,角色名查找, 用登录时分配的会话ID查找.用boost::multi_index进行玩 ...

  3. multi_index_container 多索引容器

    multi_index_container是c++ boost库中的一个多索引的容器.因工作中用到了,特来测试试用. #include "stdafx.h" #include &q ...

  4. 使用boost::multi_index高速构建排行榜

    使用boost::multi_index高速构建排行榜 前几天在boost的maillist上看到boost::multi_index将要支持ranked_index(邮件内容见附件2),这实乃我等苦 ...

  5. boost::multi_index 提供一种千人在线即时排行榜的设计思路

    原文地址: http://www.limerence2017.com/2019/06/23/cpp01/ 做游戏或金融后台开发,经常会遇到设计开发排行榜的需求.比如玩家的充值排行,战力排行等等.而这种 ...

  6. boost multi_index 插入返回值

    boost multi_index 对象插入函数emplace() 的返回值,是一个std::pair<iterator, bool>该pair 的first 是一个插入成功的位置,第二个 ...

  7. boost multi_index简单了解

    #include <string> #include <iostream> #include <boost/multi_index_container.hpp> # ...

  8. boost之数据结构和容器

    1.静态数组array,boost对静态数组进行了封装,使用和普通数组一样的初始化式进行初始化. #include <iostream> #include <boost/array. ...

  9. BFS/DFS算法介绍与实现(转)

    广度优先搜索(Breadth-First-Search)和深度优先搜索(Deep-First-Search)是搜索策略中最经常用到的两种方法,特别常用于图的搜索.其中有很多的算法都用到了这两种思想,比 ...

随机推荐

  1. jmeter 分布式压测

    1.配置主机名称 查看主机名 hostname 配置主机别名 vim /etc/hosts 2.分布式主机也需要配置主机别名 3.每个主机上必需有JAVA环境和jmeter环境 4.如果脚本有参数文件 ...

  2. linux 堆栈查看

    top -c 查看进程ID pstree PID 查看线程树 pstack PID 查看堆栈

  3. [Linux] linux下vim对于意外退出的文档的再次开启

    转载自博客:https://blog.csdn.net/ljp1919/article/details/48372615 1.对于同一个文件如果上次已经打开,而未关闭的情况下,又打开该文件进行编辑时, ...

  4. JAVASE知识点总结(二)

    第十三章:多态  一.instanceof 判断一个类是否是指定的类 真则返回true 假则返回false.  二.字段没有多态,只有方法有多态,字段前面是的什么类型,字段就调用谁的,在编译时就已经确 ...

  5. ASP.NET 服务端接收Multipart/form-data文件

    在网络编程过程中需要向服务器上传文件. Multipart/form-data是上传文件的一种方式. /// <summary> /// 上传工程文件 /// </summary&g ...

  6. TypeScript中使用getElementXXX()

    如果只是看解决方法,可以直接跳到第二小节 简述 Angular 1.x版本是用JavaScript编写的,我们在百度Angular经常会搜索到AngularJS,并不是JavaScript的什么衍生版 ...

  7. opencv之霍夫曼变换

    霍夫变换不仅可以找出图片中的直线,也可以找出圆,椭圆,三角形等等,只要你能定义出直线方程,圆形的方程等等. 不得不说,现在网上的各种博客质量真的不行,网上一堆文章,乱TM瞎写,误人子弟.本身自己就没有 ...

  8. mysql having和using使用

    1.having当用到聚合函数sum,count后,又需要筛选条件时,就可以考虑使用having,因为where是在聚合前筛选记录的,无法和统计函数一起使用,而having在聚合后筛选记录,可以和统计 ...

  9. 学习Python基础的整体概要

  10. Disruptor—核心概念及体验

    本文基于最新的3.4.2的版本文档进行翻译,翻译自: https://github.com/LMAX-Exchange/disruptor/wiki/Introduction https://gith ...