BOOST_FUSION_ADAPT_STRUCT 没有采用正确数量的参数
我正在使用 Boost::Spirit 将一些文本解析为结构。这需要使用 BOOST_FUSION_ADAPT_STRUCT 来解析文本并直接存储到结构中。我知道该宏需要 2 个参数:结构名称作为第一个参数,所有结构成员作为第二个参数。我只传递了那些 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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最有可能的问题是
std::pair
。问题是类型中有一个逗号,这会对宏扩展造成严重破坏(当使用列表的最后一个元素时)。
您应该尝试将类型括在其自己的一组括号中。
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.