DrI*_*IDK 3 c++ boost boost-spirit c++14 boost-spirit-x3
Spirit X3解析器函数使用1 attribut可以很好地工作.当我尝试使用多个属性编译文档中的代码时,它不起作用.
#include <boost/spirit/home/x3.hpp>
#include <iostream>
using namespace std;
using namespace boost::spirit;
string a = "3.2 4.5";
auto begin = a.begin();
auto end = a.end();
double d1 = 0.0, d2 = 0.0;
x3::phrase_parse(begin, end ,
x3::double_ >> x3::double_,
x3::space,
d1, d2); // doesn't work. Accept only 1 attribut
Run Code Online (Sandbox Code Playgroud)
它返回以下错误:
/home/sacha/Dev/vql/vqlcompiler.cpp:20: erreur : no matching function for call to ‘phrase_parse(__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >&, __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >&, boost::spirit::x3::sequence<boost::spirit::x3::real_parser<double>, boost::spirit::x3::real_parser<double> >, const space_type&, double&, double&)’
x3::double_ >> x3::double_, x3::space, d1, d2);
^
Run Code Online (Sandbox Code Playgroud)
似乎它不是一个可变参数模板.那么,是我还是文件?
确实.在X3中,可变超载被丢弃.
我打赌这是自从Spirit V2以来从设计中消除不必要的复杂情况的一般制度的一部分.
当然,您可以轻松地自己包装一个:
auto parse = [](auto& b, auto e, auto const& p, auto&... binds) {
auto attr = std::tie(binds...);
return x3::phrase_parse(b, e, p, x3::space, attr);
};
Run Code Online (Sandbox Code Playgroud)
#include <boost/fusion/adapted/std_tuple.hpp>
#include <boost/spirit/home/x3.hpp>
#include <iostream>
namespace x3 = boost::spirit::x3;
int main() {
auto parse = [](auto& b, auto e, auto const& p, auto&... binds) {
auto attr = std::tie(binds...);
return x3::phrase_parse(b, e, p, x3::space, attr);
};
std::string const s = "3.2 4.5";
double d1, d2;
auto begin = s.begin(), end = s.end();
if (parse(begin, end, x3::double_ >> x3::double_, d1, d2)) {
std::cout << "Parsed: " << d1 << ", " << d2 << "\n";
} else {
std::cout << "Parse failed\n";
}
if (begin != end)
std::cout << "Remaining unparsed input: '" << std::string(begin, end) << "'\n";
}
Run Code Online (Sandbox Code Playgroud)
打印
Parsed: 3.2, 4.5
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
180 次 |
| 最近记录: |