Boost Spirit optional parser and backtracking
问题 Why this parser leave 'b' in attributes, even if option wasn't matched? using namespace boost::spirit::qi; std::string str = "abc"; auto a = char_("a"); auto b = char_("b"); qi::rule<std::string::iterator, std::string()> expr; expr = +a >> -(b >> +a); std::string res; bool r = qi::parse( str.begin(), str.end(), expr >> lit("bc"), res ); It parses successfully, but res is "ab" . If parse "abac" with expr alone, option is matched and attribute is "aba" . Same with "aac" , option doesn't start