Boost Spirit自动分析器在一个双元组中失败

Boost Spirit Auto Parser fails for a tuple of doubles

本文关键字:一个 元组 失败 Spirit 分析器 Boost      更新时间:2023-10-16

在下面的代码中,我试图使用Boost Spirit Auto Parser来处理一个或两个双精度序列,但它无法编译。我在这里做错了什么?

// file main.cpp
#include <boost/tuple/tuple.hpp>
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
int main()
{
    boost::tuple<double, double> p;
    char* i = 0;
    qi::phrase_parse( i, i, p, qi::space );
    // qi::phrase_parse( i, i, qi::double_ >> qi::double_, qi::space, qi::skip_flag::postskip, p );
    return 0;
}

注释掉的行进行编译,因此它接受boost::tuple<double, double>作为qi::double_ >> qi::double_的属性类型;但是它无法从属性类型中获得解析器。为什么?

这与您的另一个问题中的答案相同-请使用boost::fusion::vector

如果我在你的程序中添加以下include,它会为我编译(g++4.6.1/boost 1.46.1):

#include <boost/fusion/adapted/boost_tuple.hpp>

我相信这将boost::tuple调整为符合boost::fusion序列,由sequence复合属性规则要求:

http://www.boost.org/doc/libs/1_48_0/libs/spirit/doc/html/spirit/qi/quick_reference/compound_attribute_rules.html

Graham