2
这是一个代码示例。用boost :: spirit解析双精度列表
// file temp.cpp
#include <iostream>
#include <vector>
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
struct parser : qi::grammar<std::string::const_iterator, std::vector<double> >
{
parser() : parser::base_type(vector)
{
vector = +qi::double_;
}
qi::rule<std::string::const_iterator, std::vector<double> > vector;
};
int main()
{
std::string const x("1 2 3 4");
std::string::const_iterator b = x.begin();
std::string::const_iterator e = x.end();
parser p;
bool const r = qi::phrase_parse(b, e, p, qi::space);
// bool const r = qi::phrase_parse(b, e, +qi::double_, qi::space); // this this it PASSES
std::cerr << ((b == e && r) ? "PASSED" : "FAILED") << std::endl;
}
我想分析std::string
x
与parser
p
。
如从的struct parser
定义如下,线条
qi::phrase_parse(b, e, p, qi::space); // PASSES
和
qi::phrase_parse(b, e, +qi::double_, qi::space); // FAILS
应该是等效的。但是,第一个解析失败,第二个解析失败。
我在做什么错在struct parser
的定义?