boost :: spirit :: x3中的connathesting std ::对属性属性
Synthesizing std::pair attributes in boost::spirit::x3
我正在尝试使用boost :: spirit :: x3创建一个解析器,并偶然发现了一个奇怪的问题。尽管如此,乔尔·德·古兹曼(Joel de Guzman)和迈克尔·凯斯(Michael Caisse)(https://ciere.com/cppnow15/)在"使用X3"文档中介绍了这种特殊用例,但并不是所有的广告功能似乎都起作用。
问题是Spirit X3显然难以合成元组属性,例如std :: paip。因此,以下构造声称产生了具有一对字符串类型的属性:
auto item = rule<class item, std::pair<std::string, std::string>>()
= name >> ’:’ >> ( quote | name );
琐碎的示例:
#include <iostream>
#include <vector>
#include <boost/spirit/home/x3.hpp>
using namespace std;
namespace x3 = boost::spirit::x3;
using x3::int_;
int main()
{
string input = "foo: 146 n"
"the_answer: 42 n"
"freeze_point: 0 n";
cout << input << endl << endl;
auto identifier = x3::rule<class identifier, string>()
= x3::lexeme[(x3::alpha | '_') >> *(x3::alnum | '_')];
auto key_value_pair = x3::rule<class key_value_pair, pair<string, int>>()
= identifier >> ':' >> int_;
auto first = input.begin();
auto last = input.end();
vector<pair<string, int>> output;
bool result = x3::phrase_parse(first, last, *(key_value_pair), x3::space, output);
cout << endl << "Result:" << result << endl << (first - input.begin()) << " of " << (last - input.begin());
return 0;
}
生活在科里鲁: http://coliru.stacked-crooked.com/a/8980ba6215ae0ce7
此代码无法编译,编译器抱怨尝试将INT分配给一对。精神为什么这样做是这样做的,而不是提取两个值(分别是字符串和int)并将它们放在一对中?不确定这是否是BOOST :: Spirit :: X3中的错误,也许我做错了什么。
编译器尝试:Apple-Clang,GCC,MSVC17。Boost版本为1.66或1.69。
您缺少:
#include <boost/fusion/adapted/std_pair.hpp>
包含包含STD ::配对所需的模板中的模板。
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- C++删除未使用的类属性会导致 std::logic_error
- 将图形属性与 std::unique_ptr 捆绑在一起
- 警告:忽略模板参数上的属性..在 std::unique_ptr (-wignore 属性)的声明中
- 在使用 std::sort() 和 lambda 函数按属性对 ADT 的向量进行排序时遇到问题
- 使用 Spirit 将 std::vector<std::vector<double> 解析为结构属性
- 更改 std::set 作为成员属性的顺序
- 不同编译器中的STD容器的不同NOExcept属性
- boost :: spirit :: x3中的connathesting std ::对属性属性
- std::vector中的对象未正确保存属性
- 有一个具有映射到 std::vector 属性的 Eigen::matrix 属性的类
- 正在使用std::string初始化istream属性
- 如何检查对象属性更新是否存在 std::map 键,否则插入一个新键?
- 如何根据结构中的属性值对std::map进行排序
- 当存储在std::vector属性中时,我可以删除析构函数中的指针吗
- 具有 std::vector 和 std::set 属性的容器
- 维护 std::p riority_queue 的堆属性
- 访问 std::list 中派生类的属性
- Boost的属性.Spirit语法:Boost::variant的std:vector错误
- 将类的std::vector作为同一类的属性是一个很好的设计选择