2
ここにコードサンプルがあります。boost :: spiritでdoubleのリストを解析する
// 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;
}
私はparser
p
でstd::string
x
を解析します。
struct parser
としての定義から、以下、ライン
qi::phrase_parse(b, e, p, qi::space); // PASSES
と
qi::phrase_parse(b, e, +qi::double_, qi::space); // FAILS
は同等であるべきです。しかし、最初の1回の解析では失敗し、2回目の解析では失敗します。
私はstruct parser
の定義で間違っていますか?