提升精神气 - 使用基于流的解析复制最后一个字母

klo*_*ffy 28 c++ boost boost-spirit libc++

这可能非常明显,但为什么boost中的基于流的解析复制了最后一个字母?我一定做错了什么:

#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"
}
Run Code Online (Sandbox Code Playgroud)

使用XCode 5.0和Boost 1.54.0进行测试.

编辑: 问题似乎是特定于libc ++.有人使用Clang护理确认吗?

eco*_*tax 1

如果我理解正确,您不应该使用输入迭代器,因为它们可能会导致回溯问题。也许这只是纯粹的运气/实现上的差异,这有时完全有效。