Boost logo

Boost Users :

Subject: Re: [Boost-users] [spirit][qi] Iteration / string iterator
From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2010-10-01 22:42:20


> On Fri, Oct 1, 2010 at 2:34 PM, alfC <alfredo.correa_at_[hidden]> wrote:
> > can anybody explain to me why this example from the Spirit.Qi manual
> > works
> >
> > http://www.boost.org/doc/libs/1_44_0/libs/spirit/example/qi/complex_nu
> > mber.cpp
> >
> > and when I try to use the string iterators directly I get a horrific
> > compiler error? Something to do with string iterators being pointers
> > or something?
> >
> > std::string s = "(2, 3)"; // < line added to example
> > bool r = phrase_parse(s.begin(), s.end(), //< only line changed
> > in the example was (first, last)
>
> You are using GCC, phrase_parse's first parameter must be non-const.
>
> Visual studio can accept a const in a non-const if it is a temporary, as
> above.
> GCC however, follows the standard, meaning that you must create an
> iterator for at least the s.begin() and pass the iterator in, not a
> temporary, meaning change the above lines to this:
>
> std::string s = "(2, 3)"; // < line added to example
> std::string::iterator iter = s.begin();
> bool r = phrase_parse(iter, s.end(), //< only line changed in the
> example was (first, last)

Starting with V2.4 (Boost V1.44) Spirit has a set of overloaded API functions allowing to pass a const iterator as the first parameter as well. Your code would work there just fine.

Regards Hartmut
---------------
http://boost-spirit.com


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net