Error compiling a spirit sample

The accepted answer to this other question will lead me to this sample, but compilation gives a long list of errors. Here is a sample code, I added only inclusions and dummy 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
}

I tried both increasing 1.42 (by default on my Ubuntu 11.04 distribution) and 1.48 (downloaded). Errors (I report QtCreator filters) vary: ver 1.42 gives

/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 tostd::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 tostd::basic_string<char>::basic_string(mpl_::void_&)’

while ver. 1.48 gives

/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>&)’

Am I missing something?

change . I found a solution: add this header and both versions compile

#include <boost/fusion/adapted/std_pair.hpp>
+5
source share
1 answer

... . , , :

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

Qi, std:: pair .

, - / , .

+5

All Articles