#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. pip版本降级

    使用命令:python -m pip install pip==8.1.1 其中, -m参数的解释 run library module as a script (terminates option ...

  2. TCGA各种肿瘤数据的20多种不同玩法/挖掘方法

    肿瘤基因组图谱 (The Cancer Genome Atlas,TCGA) 计划是由美国国家癌症研究院(National Cancer Institute,NCI)和美国国家人类基因组研究所(Nat ...

  3. PacMan 01——玩家移动

    版权申明: 本文原创首发于以下网站: 博客园『优梦创客』的空间:https://www.cnblogs.com/raymondking123 优梦创客的官方博客:https://91make.top ...

  4. Linux常用命令(常用)

    一,Linux常用命令二,CentOS没有盘符,只有根目录/,可以理解为只有一个盘有一个文件夹有点特殊,画了一个房子,代表当前用户的家 1.记住一个点:区分根目录和当前用户的家cd ~ 代表回家cd ...

  5. jenkins自动化部署项目9 --定时构建

    举几个例子:每隔5分钟构建一次H/5 * * * * 每两小时构建一次H H/2 * * * 每天中午12点定时构建一次H 12 * * * 每天下午18点定时构建一次H 18 * * * 在每个小时 ...

  6. java8 函数接口

    [前言] java8新特性 java8 Optional使用总结 java8 lambda表达式 Java 8 时间日期使用 1.函数式接口新特性 java8中引入了函数式接口新特性,使用@Funct ...

  7. 玩转 SpringBoot 2 之整合 JWT 上篇

    前言 该文主要带你了解什么是 JWT,以及JWT 定义和先关概念的介绍,并通过简单Demo 带你了解如何使用 SpringBoot 2 整合 JWT. 介绍前在这里我们来探讨一下如何学习一门新的技术, ...

  8. Git很麻烦?不存在的!掌握这几招就够了

    废话不多说,下面直接开始了! 查看原文 确保代码库是最新的,先用这条命令把你的代码拉取到本地 git clone -- 修改完代码后,按顺序执行下面四个命令 git pull git add * /r ...

  9. 微信小程序开发实战-天气小程序

    园龄6年8个月了,还一篇文章都没写过,惭愧! 最近周末做了个天气预报小程序,在这里整理一下开发过程和注意点,给对小程序开发感兴趣的伙伴们提供点参考. 废话不多说,先上图最终效果: 下面进入正文: 第一 ...

  10. ServiceStack.Redis高效封装和简易破解

    1.ServiceStack.Redis封装 封装的Redis操作类名为RedisHandle,如下代码块(只展示部分代码),它的特点: 1)使用连接池管理连接,见代码中的PooledClientMa ...