boost - 使用复合键从 multi_index_container 中删除每个键的元素

标签 boost compiler-errors boost-multi-index

我有一个 multi_index_container索引为 composite_key .
但我找不到一种方法来通过它的键删除一个元素。
请看下面:

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/composite_key.hpp>

using namespace boost::multi_index;

struct Point
{
    int x, y;
};

void func()
{
  multi_index_container<Point,indexed_by<
    hashed_unique<
      composite_key<Point,
                    member<Point,int,&Point::x>,
                    member<Point,int,&Point::y> >
      > > > points;

  points.find( boost::make_tuple( 3, 3 ) );    // <- works
  points.erase( boost::make_tuple( 3, 3 ) );   // <- failes to compile
}
erase(key)适用于非复合索引。但我找不到复合键的正确语法。

最佳答案

erase没有允许与元组互操作的重载类型(从技术上讲,这与 compatible extensions 的概念有关。)但是您可以使用更多代码获得相同的效果:

auto p=points.equal_range(boost::make_tuple(3,3));
points.erase(p.first,p.second);

关于boost - 使用复合键从 multi_index_container 中删除每个键的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12579000/

相关文章:

c++ - 使用带有 std::unique_ptr 元素的 boost::multi_index::multi_index_container 的初始化列表

c++ - 用于在 boost 多索引的序列索引中插入的匹配函数

c++ - boost 序列化: save_construct_data not called

c++ - Qt 是否有自己的 boost::optional 替代方案?

c# - 仅当从网络驱动器进行编译时,编译问题[“Root activity type is invalid”]

Java "XXX is already defined in main"错误

c++ - 如何在 multi_index_container 中添加指定的有序唯一索引

c++ - Boost 库,使用 std::wstring 作为带有 boost::property_tree::read_xml 的文件名

c++ - boost 路径包含 Mingw 的困境

python - "file"对象没有属性 '__getitem__' 并且缺少模块