Boost logo

Boost Users :

Subject: Re: [Boost-users] Spirit question
From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2010-03-17 17:31:30


> Please see attached code. Why does line A compile while line B
> doesn't? Thanks.

Here is the code (to have a reference):

    template <typename Iterator>
    struct idlist: qi::grammar<Iterator, std::string(), ascii::space_type> {

      ecgp::ident<Iterator> id;
      idlist(): idlist::base_type(start) {
        using namespace qi;
        start %= id >> (char_(',') >> id); // line A
        //start %= id >> *(char_(',') >> id); // line B
      }

      qi::rule<Iterator, std::string(), ascii::space_type> start;
    };

where the attribute of id is std::string.

The problem is an attribute mismatch of the attribute exposed by start
(which is std::string) and the rhs, which formally exposes
tuple<std::string, std::vector<std::string>>, but in addition should be
compatible with a plain std::vector<std::string> (although we know there is
a bug preventing this to compile).

If you are really just interested in the overall string matched by start's
rhs, you could write:

    start %= raw[id >> *(char_(',') >> id)];

HTH
Regards Hartmut

---------------
Meet me at BoostCon
www.boostcon.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