在c ++ 11中有Boost.Bimap替代吗? [英] Is there a Boost.Bimap alternative in c++11?

查看:192
本文介绍了在c ++ 11中有Boost.Bimap替代吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可用的替代Boost的bimap在C ++ 0x?

Is there a usable alternative to Boost's bimap in C++0x?

我想避免Boost,但完全接受C ++ 11。如果有必要,Boost的bimap的一个瘦小的版本将在我的程序中为我工作(我需要一个常量bimap在枚举和相应的字符串之间切换)。映射将是编译时常量,因此,甚至两个手动维护的映射不是最佳解。

I would like to avoid Boost, but fully embrace C++11. If necessary, a slimmed down version of Boost's bimap would work for me (I need a constant bimap to switch between enums and corresponding strings) throughout my program. The map will be compile-time constant, so perhaps even two manually maintained maps aren't the optimal solution.

谢谢!

更新:我在代码项目中发现了,但是它似乎许可可能是一个问题: http://www.codeproject.com/KB/stl/bimap.aspx?fid=12042& df = 90& mpp = 25& noise = 3& sort = Position& view = Quick& fr = 151#xx0xx

UPDATE: I found this on The Code Project, but it seems licensing may be an issue: http://www.codeproject.com/KB/stl/bimap.aspx?fid=12042&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=151#xx0xx

一个干净和容易的解决方案(一个标题/源文件或一点额外,因为两个镜像映射在我的情况下是同样精细)。

I'm just looking for a clean and easy solution (one header/source file or little extra, as two mirrorred maps are equally fine in my case).

推荐答案

p>我的感觉是Boost库中的许多工作正在使它们与其他库/ STL一起工作。

My feeling is a lot of the work that goes into Boost libraries is making them work with other libraries/STL.

如果你不需要这个能力,你可以只使用具有 std :: map< X *,Y *> std :: map< Y *,X *> ; 。然后有如下方法: add(X,Y) remove(X,Y) get_left(X) get_right(Y)

If you don't need that capability, you could just use a class with a std::map<X*, Y*> and std::map<Y*, X*>. Then have methods like the following: add(X,Y), remove(X,Y), get_left(X) and get_right(Y).

想要存储副本, add(X,Y)可以分配内存, remove(X,Y) -分配。此外,您可以定义一个析构函数,在其余元素上调用 remove(X,Y)

If you want to store copies, add(X,Y) could allocate memory, and remove(X,Y) can de-allocate. Also, you can then define a destructor that calls remove(X,Y) on the remainder of the elements.

这篇关于在c ++ 11中有Boost.Bimap替代吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆