Boost库中的bimap双向映射表提供了一些方便的操作符,例如operator[]。本篇文章将介绍如何使用该操作符,并呈现相应的测试程序。
首先需要在代码中包含头文件boost/bimap.hpp以及头文件boost/bimap/unordered_set_of.hpp和boost/bimap/list_of.hpp(或其他相关头文件)。下面是一个示例程序:
#include <iostream>
#include <string>
#include <boost/bimap.hpp>
#include <boost/bimap/unordered_set_of.hpp>
#include <boost/bimap/list_of.hpp>
using namespace boost::bimaps;
int main()
{
typedef bimap<unordered_set_of<std::string>, list_of<int>> bimap_type;
bimap_type bm;
// 添加键值对
bm.insert(bimap_type::value_type("one", 1));
bm.insert(bimap_type::value_type("two", 2));
bm.insert(bimap_type::value_type("three", 3));
// 使用operator[]查找值
std::cout << bm["one"] << std
订阅专栏 解锁全文
2922



被折叠的 条评论
为什么被折叠?



