2016-04-11 4 views
0

multi_indexセットでreverse_iteratorsを生成して比較する際に問題が発生しています。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)); 
} 

これは私がG ++ 5.2.1からかなり長いエラーメッセージが表示されて、逆イテレータを割り当てようとFの最後の行に失敗します。

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()と比較しようとすると失敗します。

同じタイプのreverse_iteratorを生成する方法はありますかmargin_index.rend()もlower_boundの対数的複雑さを保持していますか?

+0

私はそれをより読みやすくするために(http://pastebin.com/dWKGGdem)[エラーメッセージを書式設定しました] 。 'std :: reverse_iterator'ではなく' #include 'と' boost :: iterator :: reverse_iterator'を試しましたか? (BTWでは、完全なコード例を投稿し、問題が解決されたときにコンパイルします。これは含まれていないので、 'IndexComparator'や' ordered_indexes'のような未定義の記号がいくつかあります) –

答えて

1

必要としない、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)); 
関連する問題