c++ - lambda 在 boost spirit 的惰性参数中不被接受

标签 c++ boost boost-spirit boost-spirit-qi

eps 接受计算 bool 的惰性参数。

我一直在将 eps 与诸如 eps(_r1 == 0) >> something 之类的 pheonix 对象一起使用,并且有效。

但是,当我将 lambda 函数用于无法以 pheonix 形式表达的更复杂的表达式时,会引发静态断言并且无法编译。

auto test_lazy_arg_f = [](const auto&, const auto& context) {
  return true;
}

boost::spirit::qi::eps(test_lazy_arg_f) >> whatever_i_need;

编译失败,出现以下错误:

/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 (感谢 Nikita Kniazev)

我没有看到 spirit 文档中对惰性参数的任何限制。

如何使用非 pheonix 函数对象?

最佳答案

显示的代码无法重现您的问题 (https://wandbox.org/permlink/uE5ONUXCjuX7j4Mt)。我假设您的意思是在更多上下文中。

我认为“原始函数签名”仅适用于完全匹配(不方便正确且难以维护,请参阅 boost spirit semantic action parameters)。

因此,要将任何可调用对象(您的多态 lambda 就是这样的东西)变成 Phoenix actor,请使用 phoenix::bind .我个人喜欢用 phoenix:function<>包装我的可调用对象。

我有很多这样的例子,但是请看例如boost spirit semantic action using non-void function objects

关于c++ - lambda 在 boost spirit 的惰性参数中不被接受,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54395924/

相关文章:

c++ - 从作为守护进程启动的应用程序打开外部应用程序

c++ - 如何通过索引访问 boost::multi_index::multi_index_container<> 的所有元素?

c++ - 通过引用传递数组到线程

c++ - C++11 中对数组的右值引用的目的是什么?

c++ - 标记化字符串,接受 CPP 中给定字符集之间的所有内容

c++ - boost 日志旋转文件 - 超出大小

parsing - 我可以从我的船长解析器收集属性吗?

c++ - 提升精神: parse boolean expression and reduce to canonical normal form

c++ - 使用来自 Boost.Spirit 的 Lex 和 Qi 在语法规则中使用词法分析器标记属性

c++ - 为 MinGW boost 二进制文件