[Spirit] [Fusion] Concise way to construct attribute object

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Spirit] [Fusion] Concise way to construct attribute object

Boost - Users mailing list
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 mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users