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
的定義?