Subject: [Boost-bugs] [Boost C++ Libraries] #6750: istream_iterator in spirit might have defect
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-03-31 02:25:15
#6750: istream_iterator in spirit might have defect
---------------------------------------------+------------------------------
Reporter: Li He <I.demonstrate@â¦> | Owner: djowel
Type: Bugs | Status: new
Milestone: To Be Determined | Component: spirit
Version: Boost 1.49.0 | Severity: Problem
Keywords: istream_iterator |
---------------------------------------------+------------------------------
The following program yields a wrong parsing result:
{{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
namespace spirit = boost::spirit ;
namespace qi = boost::spirit::qi ;
namespace ascii = boost::spirit::ascii ;
namespace phoenix = boost::phoenix ;
using qi::double_ ;
using qi::_1 ;
using phoenix::push_back ;
using phoenix::ref ;
int
main (int argc, char* argv[]) {
spirit::istream_iterator iter (std::cin), end ;
std::vector<double> v ;
bool r = spirit::qi::phrase_parse
(iter, end,
double_ [push_back (ref(v), _1)] % ',',
ascii::space) ;
if (r) {
std::cout << "vector: " ;
std::copy (v.begin(), v.end(),
std::ostream_iterator<double> (std::cout, ", ")) ;
std::cout << std::endl ;
}
return 0 ;
}
}}}
You may test it with input like "1,2,3,4" and the output is "vector:
1,2,3,44,". When we switch to std::getline and use the
std::string::const_iterator, the result turns out fine.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/6750> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:09 UTC