0

ブースト マルチ インデックスのシーケンス インデックスに関する非常に簡単な質問があります。コードは次のとおりです。

Link.hpp に保存されている私のクラス:

#include <string>

class Link  {
public:
    Link(std::string l,std::string r) :linkID(l),roadName(r) {}
    Link() {}
    std::string roadName;
    std::string linkID;

};

そして主な機能:

#include "Link.hpp"
#include <string>
#include <iostream>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/key_extractors.hpp>

using boost::multi_index::multi_index_container;
using boost::multi_index::ordered_non_unique;
using boost::multi_index::ordered_unique;
using boost::multi_index::sequenced;
using boost::multi_index::indexed_by;
using boost::multi_index::member;

typedef boost::multi_index::multi_index_container<Link,
        indexed_by<sequenced<> > > Links;

int main() {
    Links Ls;
    Ls.insert(Link("123", "456"));

    return 1;
}

sequenced<> が存在する場合、コンパイルにより、理解できないエラーが発生します。それを手伝ってくれませんか?

エラー:

$ g++ Links.cpp 
Links.cpp: In function ‘int main()’:
Links.cpp:29:29: error: no matching function for call to ‘boost::multi_index::multi_index_container<Link, boost::multi_index::indexed_by<boost::multi_index::sequenced<> > >::insert(Link)’
Links.cpp:29:29: note: candidates are:
/usr/include/boost/multi_index/sequenced_index.hpp:267:28: note: std::pair<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::sequenced_index_node<typename SuperMeta::type::node_type> >, bool> boost::multi_index::detail::sequenced_index<SuperMeta, TagList>::insert(boost::multi_index::detail::sequenced_index<SuperMeta, TagList>::iterator, boost::multi_index::detail::sequenced_index<SuperMeta, TagList>::value_param_type) [with SuperMeta = boost::multi_index::detail::nth_layer<1, Link, boost::multi_index::indexed_by<boost::multi_index::sequenced<> >, std::allocator<Link> >, TagList = boost::mpl::vector0<mpl_::na>, typename SuperMeta::type::node_type = boost::multi_index::detail::index_node_base<Link, std::allocator<Link> >, boost::multi_index::detail::sequenced_index<SuperMeta, TagList>::iterator = boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::sequenced_index_node<boost::multi_index::detail::index_node_base<Link, std::allocator<Link> > > >, boost::multi_index::detail::sequenced_index<SuperMeta, TagList>::value_param_type = const Link&]
/usr/include/boost/multi_index/sequenced_index.hpp:267:28: note:   candidate expects 2 arguments, 1 provided...................
4

2 に答える 2

3

insert挿入するコンテナー内の場所を指定するための最初の引数として反復子が必要です。もあるように見えmulti_index_containerますがpush_back、これはおそらくあなたが望むものに近いでしょう。

したがって、シーケンスの先頭に挿入するには:

Ls.insert( Ls.begin(), Link( "123", "456" ) );

またはその後ろに:

Ls.push_back( Link( "123", "456" ) );
于 2012-03-26T08:34:22.433 に答える
0

挿入に1つのパラメーター、つまり挿入される値のみが必要な新しいバージョンのboostで機能しています。一方、push_back メソッドは削除されています。

于 2020-07-30T00:45:51.213 に答える