boost::multi_index的替代方法
Alternatives for boost::multi_index
我想使用一些可以创建字典的东西,如
多键
Key1 which will map to SomeObject
Key2
Key3
Key4
etc
我想根据任意键查找。我对boost::multi_index有奇怪的问题,正在寻找替代方案。
我的编译器是Visual Studio 2005和我使用boost和不使用c++ 11。任何boost(除了multi_index)的东西都是非常受欢迎的。
当然,您应该解决您的奇怪问题,但这里有一个很好的技术:
std::vector<X> v; // elements of X in some order
std::vector<std::reference_wrapper<X const> > index1(v.begin(), v.end());
std::vector<std::reference_wrapper<X const> > index2(v.begin(), v.end());
// sort the indexes
std::sort(index1.begin(), index1.end(), by_property1);
std::sort(index2.begin(), index2.end(), by_property2);
当然,在发生变化的情况下保持同步并控制索引排序的运行时成本是一项稍微棘手的任务,这就是为什么—大多数时候—您希望multi_index_container
另外,请注意,为了更无忧无虑,您需要将vector
替换为list
,以享受迭代器/引用的稳定性。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 在提升multi_index容器中,是否定义了"default index"?
- 通过方法访问结构
- 最小硬币更换问题(自上而下方法)
- C++为构建时间获取QDateTime的可靠方法
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 处理多个异常集合的C++方法
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 有什么方法可以遍历结构吗
- 当类在C++中定义时,有什么方法可以"register"类吗?
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- 使用std::函数映射对象方法
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- C++从另一个类访问公共静态向量的正确方法是什么
- C++优先级队列,按对象的唯一指针的特定方法升序排列
- 没有为自己的结构调用列表推回方法
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- 在类定义之后定义一个私有方法
- 在c++中把map (value,index)转换成vector (index,value)的最快方法是什么?