Boost logo

Boost Users :

From: Phil Endecott (spam_from_boost_users_at_[hidden])
Date: 2021-03-28 14:20:52


Dear Experts,

I currently have something like:

struct S {
   string name;
   string value;
};

BOOST_FUSION_ADAPT_STRUCT( S, name, value )

using S_rule = qi::rule<ITER, skipper, S()>;

S_rule r %= identifier >> lit(':') >> identifier;

Note that I can use %= here and I don't need to write an explicit
semantic action to assign to S.

Now say I modify S:

class S
{
public:
   S(string name_, string value_);
   // May be default-constructable, copyable, assignable etc.
   // - but name and value are not individually assignable.
};

Question: what is the best way to use that with the qi parser rule?

I was hoping to find something in Fusion that would allow me to adapt the
new class so that it can be used with %= as before, but I don't see anything
appropriate.

Currently the best that I can think of is:

S_rule r = ( identifier >> lit(':') >> identifier )
            [ _val = boost::phoenix::construct<S>(_1,_2) ];

How can I improve on that?

Thanks, Phil.


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