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;
}
나는 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
은 동일해야한다. 그러나 첫 번째 구문 분석은 실패하고 두 번째 구문 분석은 통과합니다.
내가 struct parser
의 정의에서 잘못하고있는 것은 무엇입니까?