Re: newbie here ask about qi::_val and semantic action

Seth <[email protected]> Mon, 9 Jul 2018 16:44:58 +0200
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
On 09-07-18 07:38, Yi Leong wrote:
> yeah, in the qi::double_[qi::_val = qi::_1] , the semantic action is a
> lambda expression

no, that is not a lambda expression

> The above code gets compiling error, so  is the placeholder qi::_val 
> usable only in the lambda expression, right?
No. The placeholder is a lazy (phoenix) actor that can be composed into
a semantic action. You **can** compose and use phoenix actors outside
Spirit semantic actions, but the (you guessed it) _semantics_ of the
placeholders will only be the same when used with the Qi context.

To use free functions as semantic actions, learn about the "Anatomy Of
Semantic Actions"
(http://boost-spirit.com/home/2010/03/03/the-anatomy-of-semantic-actions-in-qi/comment-page-1/).
The best source I've seen is this Stackoverflow post:
https://stackoverflow.com/questions/3066701/boost-spirit-semantic-action-parameters/3067881#3067881

I'd recommend not going "naked functions", but instead adapting with
`boost::phoenix::function<>'.



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general