2016-04-11 8 views
0

Ich habe einige Probleme beim Generieren und Vergleichen Reverse_iterators auf einem Multi_index-Set.arbeiten mit boost :: 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)); 
} 

Dies scheitert in der letzten Zeile von f, wo ich versuche, ein Reverse-Iterator zuweisen, mit dem ziemlich langen Fehlermeldung von 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 

Es scheint, dass sagen zu std :: reverse_iterator erzeugt keinen reverse_iterator vom richtigen Typ. Ich habe versucht, es zu beheben, indem ich die Typdeklaration von "it" in auto ändere, aber es schlägt immer noch fehl, wenn ich versuche, mit margin_index.rend() zu vergleichen

Gibt es eine Methode, einen reverse_iterator vom gleichen Typ zu erzeugen als margin_index.rend(), wodurch auch die logarithmische Komplexität von lower_bound erhalten bleibt?

+0

I [formatiert die Fehlermeldung] (http://pastebin.com/dWKGGdem) es besser lesbar zu machen . Haben Sie '#include ' und 'boost :: iterator :: reverse_iterator' anstelle von' std :: reverse_iterator' versucht? (Übrigens sollten Sie ein Code-Beispiel veröffentlichen, das vollständig ist und kompiliert wird, wenn das Problem gelöst ist - dieses wird nicht, da es keine Includes und einige undefinierte Symbole wie "IndexComparator" oder "ordered_indexes" gibt) –

Antwort

1

nicht std::reverse_iterator Verwenden Sie nicht benötigt:

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

oder

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