作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想创建一个解析字符串和 float 的 boost spirit 规则。我要解析的字符串格式如下:
(str astring)(n 123)
或者也可以是另一种顺序:
(n 123)(str astring)
我想创建一个具有以下类型属性的规则:
qi::rule<Iter, boost::fusion::vector<std::string, float>, ascii::space_type> hj;
到目前为止,这是我的代码:
qi::rule<Iter, std::string(), ascii::space_type> attr;
attr = lexeme[*alnum];
qi::rule<Iter, boost::fusion::vector<std::string, float>, ascii::space_type> hj;
hj = (
'(' >> lit("str") >> attr(/*put this at position 0*/) >> ')'
|
'(' >> lit("n") >> float_[/*put this at position 1*/] >> ')'
);
显然,这并不能编译(boost 扣除了另一个属性类型)。我该如何实现这一点,特别是我应该在注释代码中添加什么?
最佳答案
您可以使用置换运算符 ^
。最小工作示例:
boost::fusion::vector<std::string,float> ans;
bool res = phrase_parse(first,last,
(lit("(") >> lit("str") >> lexeme[*ascii::alnum] >> lit(")") ) ^
(lit("(") >> lit("n") >> float_ >> lit(")") ),
ascii::space,ans);
更详细地描述了此解决方案 here .
关于c++ - 提振精神或秩序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20243600/
这个问题已经有答案了: Can a private method in super class be overridden in the sub-class? (12 个回答) 已关闭 6 年前。 我
我有一个从表中获取所有列的查询,然后我做了一些工作。问题是我使用插入的列名,但由于 Get-Member,它们的顺序不同。有没有办法获取属性名称(列名称)并维护顺序或重新排序 System.Data.
我是一名优秀的程序员,十分优秀!