c++ - Boost 多索引有序迭代器分配

标签 c++ boost multi-index

我有一个 boost multi_index_container,存储了一堆具有以下索引的位置

boost::multi_index::indexed_by<
    boost::multi_index::ordered_unique<
            boost::multi_index::tag<Slot>,
            boost::multi_index::identity<SlotData>
        >,  //ordered_unique
    boost::multi_index::ordered_non_unique<
            boost::multi_index::tag<Level>,
            SlotData::ExtractZ
        >,  // ordered_non_unique
...//index by
.//typedef as SlotLocations

在这个定义中,我相信默认索引将是基于Slotordered_unique。后来我有一个迭代器 SlotLocations::iterator ,我想用它来存储基于 Level 的搜索结果,即 ordered_non_unique:

typedef SlotLocations::index<Level>::iterator MIterator;

std::pair<MIterator, MIterator> range = map.get<Level>().range(..some conds..);

SlotLocations::iterator itr = range.first;    //error

范围搜索可以工作并返回存储在范围中的所需结果,但是此代码将无法使用行标记进行编译,并出现以下错误:

error: no match for 'operator='

为什么我不能像这样分配/存储迭代器?存储搜索结果迭代器的可能方法是什么?

最佳答案

您必须跨索引投影迭代器

应该是这样的

 SlotLocations::iterator itr = project<Slot>(map, range.first);

关于c++ - Boost 多索引有序迭代器分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20982739/

相关文章:

c++ - mingw makefile 编译器不输出所有内容

c++ - 在安装应用程序期间或启动应用程序时向 Mac 上的防火墙添加异常(exception)

c++ - 如何在浏览器内的网络上运行 C++ 程序?

C++在读取文件时在字符串开头添加回车符

c++ - 来自 C++ 标准容器的 boost ptr_array 的替代方案

c++ - 如何使用复合键获取 boost::multi_index_container 中第一个键的不同计数

c++ - boost.mpi 中的自定义 reduce 操作

c++ - boost::shared_ptr::shared_ptr(const boost::shared_ptr&)' 被隐式声明为已删除

python - MultiIndex DataFrame 中基于现有列级别值的新级别

Python:基于MultiIndex的彩色 Pandas 数据框