5

この他の質問に対する受け入れられた回答は、このサンプルにつながりましたが、コンパイルすると長いエラーリストが表示されます。ここにサンプル コードを示します。インクルードとダミーの main() だけを追加しました。

#include <boost/spirit/include/qi.hpp>
#include <vector>
#include <map>
#include <string>
#include <iostream>

namespace qi = boost::spirit::qi;

template <typename Iterator>
struct keys_and_values
  : qi::grammar<Iterator, std::map<std::string, std::string>()>
{
    keys_and_values()
      : keys_and_values::base_type(query)
    {
        query =  pair >> *((qi::lit(';') | '&') >> pair);
        pair  =  key >> -('=' >> value);
        key   =  qi::char_("a-zA-Z_") >> *qi::char_("a-zA-Z_0-9");
        value = +qi::char_("a-zA-Z_0-9");
    }
    qi::rule<Iterator, std::map<std::string, std::string>()> query;
    qi::rule<Iterator, std::pair<std::string, std::string>()> pair;
    qi::rule<Iterator, std::string()> key, value;
};

int main(int argc, char **argv)
{
    std::string input("key1=value1;key2;key3=value3");  // input to parse
    std::string::iterator begin = input.begin();
    std::string::iterator end = input.end();

    keys_and_values<std::string::iterator> p;    // create instance of parser
    std::map<std::string, std::string> m;        // map to receive results
    bool result = qi::parse(begin, end, p, m);   // returns true if successful
}

ブースト 1.42 (Ubuntu 11.04 ディストリビューションのデフォルト) と 1.48 (ダウンロード済み) の両方を試しました。エラー(QtCreatorによってフィルタリングされたものを報告します)が異なります:ver 1.42は

/usr/include/boost/fusion/support/tag_of.hpp:92:13: error: no matching function for call to ‘assertion_failed(mpl_::failed************ boost::mpl::not_<boost::fusion::detail::is_specialized<std::pair<std::basic_string<char>, std::basic_string<char> > > >::************)’

/usr/include/boost/spirit/home/support/attributes.hpp:409: error: no matching function for call to ‘std::basic_string<char>::basic_string(std::pair<std::basic_string<char>, std::basic_string<char> >&)’

/usr/include/boost/spirit/home/support/attributes.hpp:409: error: no matching function for call to ‘std::basic_string<char>::basic_string(mpl_::void_&)’

ながらver. 1.48を与える

/home/carlo/Projects/spirit_vect_literals-build-desktop/../../cpp/boost_1_48_0/boost/spirit/home/qi/detail/assign_to.hpp:123: error: no matching function for call to ‘std::pair<std::basic_string<char>, std::basic_string<char> >::pair(const std::basic_string<char>&)’

何か足りないものはありますか?

編集:解決策を見つけました:このヘッダーを追加すると、両方のバージョンがコンパイルされます

#include <boost/fusion/adapted/std_pair.hpp>
4

1 に答える 1

5

これを追跡しておめでとうございます...数週間前に同じエラーが発生し、何時間も無駄にしました。あなたが見つけたように、解決策はこれを含めることです:

#include <boost/fusion/adapted/std_pair.hpp>

これは、Qi がルールの出力として std::pair を使用するために必要な魔法を提供します。

質問が未回答として表示されないように、主にこの回答をここに残しています。独自の回答を追加/受け入れたい場合は、これを撤回します。

于 2012-02-21T01:36:52.093 に答える