So what I am trying to do is to parse a list of strings:
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
std::string TEST = "aa\nbbbb\nccc\n";
std::istringstream INPUT (TEST);
std::noskipws(INPUT);
typedef std::istreambuf_iterator<char> base_iterator;
typedef boost::spirit::multi_pass<base_iterator> multi_pass_iter;
typedef boost::spirit::classic::position_iterator2<multi_pass_iter> pos_iterator;
base_iterator base_begin(INPUT);
multi_pass_iter first = boost::spirit::make_default_multi_pass(base_begin);
multi_pass_iter last;
pos_iterator pfirst(first,last,std::string("DD"));
pos_iterator plast;
using qi::lexeme;
using ascii::alpha;
std::vector<std::string> DDD;
bool res = qi::phrase_parse(pfirst,plast,* lexeme[+alpha],ascii::space,DDD);
for (const auto & d : DDD) std::cout << d << " (" << d.size() << ")" << std::endl;
What i get in DDD are 3 strings of the correct size, but all of whitespaces.
If instead i use
bool res = qi::phrase_parse(first,last,* lexeme[+alpha],ascii::space,DDD);
everything works as expected.
I used position_iterator2 in the past without any problem, so I don’t believe it is a bug. Am I missing something?
There is an example here that doesn’t work either. Using Visual Studio 2012 both give a warning:
A quick google search of “iterator_adaptor dereference temporary” leads to this that recommends that the
Referenceparameter ofiterator_adaptorbe a non-reference type.In order to accomplish that you need to change the file “boost/spirit/home/classic/iterator/impl/position_iterator.ipp”. Specifically you’d need to change:
to:
this leads to a new error in both g++ and vc11:
That can be avoided if you change the
iterator_adaptortypedef to:This makes both the program below (based on your code) and the example from boost-spirit.com work, but I’m not sure that it won’t break in other cases, so use it at your discretion.