BOOST_FUSION_ADAPT_STRUCT没有采用正确数量的参数

Nik*_*Nik 9 c++ boost boost-fusion boost-spirit-qi

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

error: macro "BOOST_FUSION_ADAPT_STRUCT_FILLER_0" passed 3 arguments, but takes just 2
Run Code Online (Sandbox Code Playgroud)

这是代码片段.如果您需要整个代码,请告诉我.

谢谢.

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))
Run Code Online (Sandbox Code Playgroud)

这是我试图解析的规则,

qi::rule<Iterator, Dir_Entry_Pair()> ppair  =   dir
                                                >>  '/'
                                                >>  entry
                                                >> -(keyword >> entry);
Run Code Online (Sandbox Code Playgroud)

Mat*_* M. 12

最有可能的问题是std::pair<std::string,std::string>.

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

您应该尝试将类型包装在其自己的括号中.

  • 谢谢 !我只是键入了std :: pair &lt;..&gt;而它起作用了:) (2认同)