eps
accepts a lazy argument that evaluates bool.
I've been using eps
with pheonix objects like eps(_r1 == 0) >> something
, and it has worked.
However, when I use a lambda function for more complex expression that can't be expressed in a pheonix form, static assertion is raised and fails to compile.
auto test_lazy_arg_f = [](const auto&, const auto& context) {
return true;
}
boost::spirit::qi::eps(test_lazy_arg_f) >> whatever_i_need;
This fails to compile with the following error:
/usr/include/boost/spirit/home/qi/nonterminal/rule.hpp:177:13: error: static assertion failed: error_invalid_expression
BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
https://wandbox.org/permlink/eiM6zDfyzuapcQtB (Thanks Nikita Kniazev)
I don't see any restriction on lazy arguments in spirit documentations.
How can I use non-pheonix function object?
The code shown can't reproduce your issue (https://wandbox.org/permlink/uE5ONUXCjuX7j4Mt). I assume you meant in more context.
I think the "raw function signature" only works for exact matches (which are inconvenient to get right and hard to maintain, see boost spirit semantic action parameters).
So to make any callable object (your polymorphic lambda is such a thing) into a Phoenix actor, use phoenix::bind
. I personally like to use phoenix:function<>
to wrap my callable objects.
I have many examples of that, but see e.g. boost spirit semantic action using non-void function objects