【发布时间】:2016-04-11 06:14:54
【问题描述】:
我在生成和比较 multi_index 集上的 reverse_iterator 时遇到了一些问题。
namespace mi = boost::multi_index;
typedef mi::multi_index_container<
size_t,
mi::indexed_by<
mi::ordered_non_unique<mi::identity<size_t>, IndexComparator >,
mi::hashed_unique<mi::identity<size_t> >
>
> index_set_t;
typedef index_set_t::nth_index<0>::type index_set_by_margin_t;
void f() {
index_set_by_margin_t& margin_index = ordered_indexes.get<0>();
index_set_by_margin_t::reverse_iterator it =
std::reverse_iterator<index_set_by_margin_t::iterator>
(margin_index.lower_bound(3, cmp));
}
这在 f 的最后一行失败,我尝试分配一个反向迭代器,并带有来自 g++ 5.2.1 的相当长的错误消息:
error: conversion from ‘std::reverse_iterator<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::hashed_index_node<boost::multi_index::detail::index_node_base<long unsigned int, std::allocator<long unsigned int> >, boost::multi_index::detail::hashed_unique_tag> > > >’ to non-scalar type ‘boost::multi_index::detail::ordered_index<boost::multi_index::identity<long unsigned int>, IndexComparator, boost::multi_index::detail::nth_layer<1, long unsigned int, boost::multi_index::indexed_by<boost::multi_index::ordered_non_unique<boost::multi_index::identity<long unsigned int>, IndexComparator>, boost::multi_index::hashed_unique<boost::multi_index::identity<long unsigned int> > >, std::allocator<long unsigned int> >, boost::mpl::vector0<mpl_::na>, boost::multi_index::detail::ordered_non_unique_tag>::reverse_iterator {aka boost::iterators::reverse_iterator<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::hashed_index_node<boost::multi_index::detail::index_node_base<long unsigned int, std::allocator<long unsigned int> >, boost::multi_index::detail::hashed_unique_tag> > > >}’ requested
似乎是在说 std::reverse_iterator 没有产生正确类型的 reverse_iterator。我试图通过将“it”的类型声明更改为 auto 来修复它,但是在尝试与 margin_index.rend() 进行比较时它仍然失败
是否有某种方法可以生成与 margin_index.rend() 相同类型的 reverse_iterator,同时保留 lower_bound 的对数复杂度?
【问题讨论】:
-
我 formatted the error message 让它更清晰。您是否尝试过
#include <boost/iterator/reverse_iterator.hpp>和boost::iterator::reverse_iterator而不是std::reverse_iterator? (顺便说一句,您应该发布一个完整的代码示例,并在问题解决后编译——这个不会,因为没有包含,以及一些未定义的符号,如IndexComparator或ordered_indexes)
标签: c++ boost boost-multi-index