BOOST_FUSION_ADAPT_STRUCT没有使用正确数量的参数。

10

我正在使用Boost::Spirit将一些文本解析为结构体。这需要使用BOOST_FUSION_ADAPT_STRUCT来解析文本并直接存储到结构中。我知道这个宏需要2个参数:第一个参数是结构体名称,第二个参数是所有结构体成员。我已经传递了这两个参数,但是编译时出现了错误:

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

这是代码片段。如果需要完整的代码,请告诉我。

谢谢。

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))

这是我正在尝试解析的规则,

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

13

很可能问题出在std::pair<std::string,std::string>这里。

问题在于类型中有逗号,这会对宏展开造成麻烦(当使用列表的最后一个元素时)。

您应该尝试将类型包装在自己的一组括号中。


1
@Nik:这是宏常见的问题,通常在使用BOOST_FOREACH遍历map时会出现,这比Fusion/Spirit组合略为常见:) 希望你使用它们很开心! - Matthieu M.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接