This may be very obvious, but why does the stream-based parsing in boost duplicate the last letter? I must be doing something wrong:
#include <iostream>
#include <sstream>
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
int main() {
std::string input = "hello";
std::stringstream ss(input);
std::string r1, r2;
boost::spirit::istream_iterator first(ss), last;
qi::phrase_parse(input.begin(), input.end(), qi::lexeme[qi::alpha >> *qi::alnum], qi::space, r1);
std::cout << r1 << std::endl; // prints "hello"
qi::phrase_parse(first, last, qi::lexeme[qi::alpha >> *qi::alnum], qi::space, r2);
std::cout << r2 << std::endl; // prints "helloo"
}
Tested with XCode 5.0 and Boost 1.54.0.
Edit: The problem seems to be specific to libc++. Anybody using Clang care to confirm?
If I understood correctly, you're not supposed to use input iterators, because they can give problems with backtracking. Maybe it's just sheer luck/a difference in implementation that this sometimes works at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With