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

Seth <[email protected]> Mon, 9 Jul 2018 16:49:30 +0200
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
On 09-07-18 09:17, Yi Leong wrote:
> Thanks! I made a mistake about the placeholder,  so the return value
> in the following:
>
>
> double print_action(double f)
> {
>     return f;  // this value will be assigned to the rule r's attribute d?
> }
>
> rule<std::string::const_iterator,  double() > r =
> qi::double_[&print_action];
>
> will be assigned to the rule  r's attribute d?

The confusions are too many.

If the name is `print_action` why does it return a value?

And no, you need to assign:

        qi::double_[qi::_val = boost::phoenix::bind(&print_action, qi::_1)];

even if you did 


    double modify(double& f)
    {
        return f *= 2;
    }

    rule<std::string::const_iterator,  double() > r =
    qi::double_[boost::phoenix::bind(&modify, qi::_1)];

It would not propagate because automatic propagation is inhibited in the
presence of semantic actions. The `operator%=` is there to force that:

    rule<std::string::const_iterator,  double() > r;
    r %= qi::double_[boost::phoenix::bind(&modify, qi::_1)];

------------------------------------------------------------------------------
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