【问题标题】:BOOST_FUSION_ADAPT_STRUCT doesn't take the right number of argumentsBOOST_FUSION_ADAPT_STRUCT 没有使用正确数量的参数
【发布时间】:2011-10-21 02:55:48
【问题描述】:

我正在使用 Boost::Spirit 将一些文本解析为结构。这需要使用 BOOST_FUSION_ADAPT_STRUCT 来解析文本并直接存储到结构中。我知道宏需要 2 个参数:结构名称作为第一个参数,所有结构成员作为第二个参数。我只通过了这 2 个。但是我收到一个编译错误,说,

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

这里是代码 sn-p。如果您需要完整的代码,请告诉我。

谢谢。

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

【问题讨论】:

    标签: c++ boost boost-spirit-qi boost-fusion


    【解决方案1】:

    问题很可能是std::pair&lt;std::string,std::string&gt;

    问题是类型中有一个逗号,这将对宏扩展造成严重破坏(当使用列表的最后一个元素时)。

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

    【讨论】:

    • @Nik:这是宏的常见问题——通常会出现BOOST_FOREACH 而不是map,这比 Fusion/Spirit 组合更常见 :) 希望你玩得开心那些!
    猜你喜欢
    • 2020-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多