10

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);
Nik
  • 293
  • 5
  • 14

1 Answers1

13

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.

Matthieu M.
  • 287,565
  • 48
  • 449
  • 722
  • 1
    @Nik: it's a common issue with macros -- usually comes up with `BOOST_FOREACH` over `map` which is slightly more common than the Fusion/Spirit combination :) Hopes you're having fun with those! – Matthieu M. Aug 05 '11 at 19:12