boost::multi_index 多索引容器
2024-09-01 10:46:43
#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");
}
最新文章
- C语言之链表
- arcgis地图数据集合
- 移动混合开发之android文件管理-->;flexbox,webFont。
- FZU 2193 So Hard (有限小数转换最简分数)(想法题)
- 分享Kali Linux 2016.2第49周虚拟机
- mysql5.6 TIME,DATETIME,TIMESTAMP
- java软件包的访问权限和继承
- WPF DataGrid 行头小三角
- UI编辑器
- linux 下创建管理员权限账户
- Windows窗口的尺寸和位置
- linux个人情况总结
- 关于web页面JApplet打印小票
- [LeetCode] Bus Routes 公交线路
- Zabbix通过Orabbix监控Oracle数据库
- 论文笔记:Batch Normalization
- java web filter读取classpath配置文件内容
- iOS.Info.plist
- mac10.12.6系统配置clion编写CMakeLists文件运行opencv3
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
热门文章
- 怎么在本地建立一个Maven 项目push到码云(https://git.oschina.net)
- DirectX12 3D 游戏开发与实战第四章内容(下)
- aclocal-1.14: 未找到命令
- JavaScript之深入函数(一)
- Linux系统在开机的时候自动启动SVN
- 数据分析--numpy的基本使用
- myql忽略大小写问题解决
- 【SQL server初级】数据库性能优化二:数据库表优化
- Kubernetes 系列(二):Deployment 扩容
- 使用 .NET Core 3.0 的 AssemblyLoadContext 实现插件热加载