Nik
Nik

Reputation: 293

BOOST_FUSION_ADAPT_STRUCT doesn't take the right number of arguments

I am using Boost::Spirit to parse some text into structs. This requires using BOOST_FUSION_ADAPT_STRUCT for parsing text and directly storing into the structure. I know that the macro takes 2 arguments: the structure name as the 1st arg and all the structure members as the 2nd argument. And I am passing just those 2. But I get a compilation error saying,

error: macro "BOOST_FUSION_ADAPT_STRUCT_FILLER_0" passed 3 arguments, but takes just 2

Here is the code snippet. Let me know if you need the entire code.

Thanks.

namespace client
{
    namespace qi = boost::spirit::qi;
    namespace ascii = boost::spirit::ascii;
    namespace phoenix = boost::phoenix;

    struct Dir_Entry_Pair
    {
        std::string                 dir;
        std::string                 value1;
        std::pair<std::string, std::string> keyw_value2;
    };
}

BOOST_FUSION_ADAPT_STRUCT(
    client::Dir_Entry_Pair,
    (std::string, dir)
    (std::string, value1)
    (std::pair< std::string, std::string >, keyw_value2))

This is the rule I am trying to parse,

qi::rule<Iterator, Dir_Entry_Pair()> ppair  =   dir
                                                >>  '/'
                                                >>  entry
                                                >> -(keyword >> entry);

Upvotes: 10

Views: 1233

Answers (1)

Matthieu M.
Matthieu M.

Reputation: 299810

Most likely the issue is std::pair<std::string,std::string>.

The problem is that there is a comma in the type, which will play havoc with the macro expansion (when using the last element of your list).

You should try wrapping the type in its own set of parentheses.

Upvotes: 13

Related Questions