Spirit unable to assign attribute to single-element struct (or fusion sequence)

假装没事ソ 提交于 2019-11-28 01:57:27

I ended up realizing that the struct I defined is being used in spirit as a tuple. Because spirit will try to minimize the groups (like, an optional<int, int> is an optional<int>). Therefore, I guessed that a tuple<A> will be converted to an A. Which seems to be the case.

I was able to further reduce the test case of broken code to the following:

#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/home/qi.hpp>
#include <string>

struct ident {
    std::string a;
};

BOOST_FUSION_ADAPT_STRUCT(ident,
        (std::string, a)
        )

int main() {
    boost::spirit::qi::rule<const char*, ident()> r;
    r = boost::spirit::lexeme["abc"];
}

From the following mailing list postings (1, 2) that I found, I can work around this issue by doing:

r = boost::spirit::lexeme["abc"] >> boost::spirit::eps;

While not really elegant, it solves the problem at least. If someone else has a method to do the single element struct, I'd be greatly interested though.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!