0

I am having some trouble generating and comparing reverse_iterators on a multi_index set.

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));
}

This fails in the last line of f, where I try to assign a reverse iterator, with the rather long error message from 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

It seems to be saying that std::reverse_iterator is not producing a reverse_iterator of the correct type. I've tried to fix it by changing the type declaration of 'it' to auto, but it still then fails when trying to compare to margin_index.rend()

Is there some method for producing a reverse_iterator with the same type as margin_index.rend() which also preserves the logarithmic complexity of lower_bound?

  • I [formatted the error message](http://pastebin.com/dWKGGdem) to make it more legible. Did you try `#include ` and `boost::iterator::reverse_iterator` instead of `std::reverse_iterator` ? (BTW, you should post a code example that is complete and will compile when the problem is resolved -- this one won't, as there are no includes, and some undefined symbols like `IndexComparator ` or `ordered_indexes`) – Dan Mašek Apr 11 '16 at 06:31

1 Answers1

1

Don't use std::reverse_iterator, not needed:

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

or

index_set_by_margin_t::reverse_iterator it(margin_index.lower_bound(3, cmp));
Joaquín M López Muñoz
  • 5,243
  • 1
  • 15
  • 20