- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试通过 qi::symbols 将一些关键字处理程序(方法)映射为 boost::function 类型的值。所以如果找到关键字我想调用方法。但我无法从这张 map 绑定(bind)方法。编译器因 phoenix::bind 上的一堆错误而失败。我做错了什么?
部分代码如下:
template <typename Iterator>
struct Grammar : qi::grammar<Iterator, AST::FunctionCall(), ascii::space_type>
{
Grammar():
Grammar::base_type(query),
{
...
operand =
predicate [phoenix::bind(phoenix::at_c<0>(qi::_1), this, phoenix::at_c<1>(qi::_1))]; // **Compiler fails here**
...
predicate =
(pred_tbl > '(')
> -(primary_expr % ',')
> ')';
...
pred_tbl.add
("composing", &RQL::composing)
);
}
qi::rule<Iterator, fusion::vector<Predicate, PredicateArgList>(), ascii::space_type> predicate;
typedef std::vector<AST::Value> PredicateArgList;
typedef boost::function<void (Grammar*, const PredicateArgList& args)> Predicate;
qi::symbols<char, Predicate> pred_tbl;
void composing(const PredicateArgList& args);
};
编译器错误:
error C2903: 'result' : symbol is neither a class template nor a function template c:\work\include\boost-1_41\boost\spirit\home\phoenix\core\detail\function_eval.hpp 115
error C2039: 'result' : is not a member of 'boost::function<Signature>' c:\work\include\boost-1_41\boost\spirit\home\phoenix\core\detail\function_eval.hpp 115
error C2059: syntax error : '<' c:\work\include\boost-1_41\boost\spirit\home\phoenix\core\detail\function_eval.hpp 115
error C2238: unexpected token(s) preceding ';' c:\work\include\boost-1_41\boost\spirit\home\phoenix\core\detail\function_eval.hpp 116
error C2065: 'function_apply' : undeclared identifier c:\work\include\boost-1_41\boost\spirit\home\phoenix\core\detail\function_eval.hpp 124
error C2955: 'boost::mpl::eval_if' : use of class template requires template argument list c:\work\include\boost-1_41\boost\spirit\home\phoenix\core\detail\function_eval.hpp 125
error C2146: syntax error : missing ';' before identifier 'type' c:\work\include\boost-1_41\boost\spirit\home\phoenix\core\detail\function_eval.hpp 126
error C3254: 'boost::phoenix::detail::function_eval<2>::result<Env,F,A0,A1>' : class contains explicit override 'type' but does not derive from an interface that contains the function declaration c:\work\include\boost-1_41\boost\spirit\home\phoenix\core\detail\function_eval.hpp 126
error C2838: 'type' : illegal qualified name in member declaration c:\work\include\boost-1_41\boost\spirit\home\phoenix\core\detail\function_eval.hpp 126
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\work\include\boost-1_41\boost\spirit\home\phoenix\core\detail\function_eval.hpp 126
error C2602: 'boost::phoenix::detail::function_eval<2>::result<Env,F,A0,A1>::type' is not a member of a base class of 'boost::phoenix::detail::function_eval<2>::result<Env,F,A0,A1>' c:\work\include\boost-1_41\boost\spirit\home\phoenix\core\detail\function_eval.hpp 126
error C2868: 'boost::phoenix::detail::function_eval<2>::result<Env,F,A0,A1>::type' : illegal syntax for using-declaration; expected qualified-name c:\work\include\boost-1_41\boost\spirit\home\phoenix\core\detail\function_eval.hpp 126
最佳答案
我想丢失的链接可能是
#define BOOST_SPIRIT_USE_PHOENIX_V3
在 http://liveworkspace.org/code/3uvyb4$1 上观看直播
它打印
Hello world from 'Grammar::composing(PredicateArgList const&)' args:3
如预期。
更新 附言。我可能更喜欢像这样编写绑定(bind)调用:
Grammar(): Grammar::base_type(predicate)
{
using phx::bind;
using namespace qi;
as<PredicateArgList> coerce;
predicate =
(pred_tbl > '('
> coerce [ -(primary_expr % ',') ]
> ')')
[ phx::bind(_1, this, _2)]
;
// ...
我认为 _1
更清晰和 _2
而不是 at_c<n>
调用。
引用代码如下:
#define BOOST_SPIRIT_USE_PHOENIX_V3
#include <boost/function.hpp>
#include <boost/phoenix/fusion.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
namespace fusion = boost::fusion;
namespace ascii = boost::spirit::ascii;
namespace phx = boost::phoenix;
namespace AST
{
struct FunctionCall {};
using Value = int;
}
template <typename Iterator>
struct Grammar : qi::grammar<Iterator, AST::FunctionCall(), ascii::space_type>
{
Grammar(): Grammar::base_type(predicate)
{
using phx::bind;
using namespace qi;
as<PredicateArgList> coerce;
predicate =
(pred_tbl > '('
> coerce [ -(primary_expr % ',') ]
> ')')
[ phx::bind(_1, this, _2)]
;
pred_tbl.add
("composing", &Grammar::composing)
;
primary_expr = qi::int_;
}
typedef std::vector<AST::Value> PredicateArgList;
typedef boost::function<void (Grammar*, PredicateArgList const&)> Predicate;
qi::symbols<char, Predicate> pred_tbl;
qi::rule<Iterator, AST::Value(), ascii::space_type> primary_expr;
qi::rule<Iterator, AST::FunctionCall(), ascii::space_type> predicate;
void composing(const PredicateArgList& args)
{
std::cout << "Hello world from 'Grammar::composing(PredicateArgList const&)' args:" << args.size() << "\n";
}
};
int main()
{
const std::string input("composing (1, 2, 3)");
auto f = begin(input), l = end(input);
Grammar<decltype(f)> p;
bool ok = qi::phrase_parse(f,l,p,ascii::space);
return ok?0:255;
}
关于c++ - 如何从 spirit 语义规则绑定(bind)/调用存储在 fusion::vector 中的 boost::function?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15811875/
我需要在 nginx-ingress 版本上允许来自多个来源的请求:http://localhost:4200、http://localhost:4242 等1.7.1.但我无法对多个来源执行此操作,
我正在部署我使用 APIGILITY 开发的 API到 IIS。由于 IIS 不支持 .htaccess,我试图从 .htaccess 文件的内容创建 web.config 文件。我使用 IISv7.
我正在尝试更改上面 css 样式中的“宽度”规则。在“inspect element”中你可以看到宽度是1008px。我不希望它是 1008px 但它不会让我在 css 样式中更改它你可以看到它被“删
外部css赋值有2种方法,我用的是第一种;大多数网站使用第二种方法。我想知道我是否做错了! 第一种方法: 为几乎每个 css 规则创建一个类并在任何地方使用它们。 blah blah .f_
RDF使用 WEB 标识符 (URIs) 来标识资源,使用属性和属性值来描述资源 RDF 资源、属性和属性值 RDF使用 WEB 标识符来标识事物,并通过属性和属性值来描述资源。 关于资源、属性
我想挖掘特定的 rhs 规则。文档中有一个示例证明这是可能的,但仅适用于特定情况(如下所示)。先来一个数据集来说明我的问题: input {b=100002} 0.2500000 0.250000
我想让 nginx 从网站根目录(:http://localhost:8080/)提供一个静态文件,但它为我的代理通行证提供服务;它提供“/”规则而不是“=/”。 这是我的 nginx 配置的样子:
根据gnu make documentation , 如果一个规则通过一次调用生成多个目标(例如,一个配方执行一个带有多个输出文件的工具),你可以使用 '&:' 规则语法来告诉 make。但是,当在多
我已阅读Firebase Documentation并且不明白什么是 .contains()。 以下是文档中 Firebase 数据库的示例规则: { "rules": { "rooms"
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 6 年前。 Improv
我正在尝试做一些多态性练习,但我无法弄清楚这种多态性是如何工作的。我没有找到任何关于这种练习的深入信息。希望大家能给我一些解释。 练习1: class Top { public void m(
为了调试复杂的 XSLT 转换,我将其分为几个部分:首先构建 %.1.xml,然后使用它构建 %.2.xml ,最后构建 %.3.xml。一切正常,但如果我要求 Make 构建最后一个,Make 总是
我尝试了 hacerrank 的 slove 练习 Click我不知道如何添加这些规则: ► 它可以包含 4 个一组的数字,并用一个连字符“-”分隔。 ► 不得有 4 个或更多连续重复数字。 这是我的
我正在尝试编写一个小测验,我希望“再试一次”按钮遵循与“else”之前的“if”语句相同的规则 using System; public class Program { public stat
在我的 Spring/Boot Java 项目中,我有一组服务方法,例如以下一个: @Override public Decision create(String name, String descr
我正在阅读 Covariant virtual function .上面写着 假设 B::f 覆盖了虚函数 A::f。如果满足以下所有条件,A::f 和 B::f 的返回类型可能不同: 1) The
我工作的公司想要分发(在公共(public)链接中)具有内部签名的应用程序。我很确定 Apple 否认这种事情,但我在官方文档/契约(Contract)中没有找到任何相关信息。 有谁知道它到底是如何工
我是 CSS 新手。我观察到一个奇怪的 CSS 行为,其中一个元素具有以下 CSS 属性 .container .header{ color: #FFFFFF; font-size: 2em;
这个问题在这里已经有了答案: Is there a CSS selector for elements containing certain text? (21 个答案) 关闭 7 年前。
我有以下 CSS: workoutcal.css: .errorlist{ color:red; } 以下基本模板: base.html: {% load static %} {
我是一名优秀的程序员,十分优秀!