Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 930
Nik Avatar asked Feb 02 '23 15:02

Nik


1 Answers

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.

like image 146
Matthieu M. Avatar answered Feb 05 '23 06:02

Matthieu M.