gpt4 book ai didi

c++ - 使用 boost::multi_index reverse_iterators

转载 作者:行者123 更新时间:2023-11-28 05:44:12 25 4
gpt4 key购买 nike

我在生成和比较 multi_index 集上的 reverse_iterators 时遇到了一些问题。

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。我试图通过将“它”的类型声明更改为自动来修复它,但在尝试与 margin_index.rend() 进行比较时它仍然失败

是否有一些方法可以生成与 margin_index.rend() 类型相同的 reverse_iterator,它还保留了 lower_bound 的对数复杂度?

最佳答案

不要使用std::reverse_iterator,不需要:

index_set_by_margin_t::reverse_iterator it = 
index_set_by_margin_t::reverse_iterator(margin_index.lower_bound(3, cmp));

index_set_by_margin_t::reverse_iterator it(margin_index.lower_bound(3, cmp));

关于c++ - 使用 boost::multi_index reverse_iterators,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36541100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com