C++ Boost spirit x3和x27;不能使用多属性
Spirit X3解析器函数使用1 attribute运行良好。当我尝试从具有多个属性的源代码编译代码时,它不起作用C++ Boost spirit x3和x27;不能使用多属性,c++,boost,c++14,boost-spirit,boost-spirit-x3,C++,Boost,C++14,Boost Spirit,Boost Spirit X3,Spirit X3解析器函数使用1 attribute运行良好。当我尝试从具有多个属性的源代码编译代码时,它不起作用 #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(); doub
#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
#包括
#包括
使用名称空间std;
使用名称空间boost::spirit;
字符串a=“3.2 4.5”;
自动开始=a.begin();
自动结束=a.end();
双d1=0.0,d2=0.0;
短语解析(开始,结束,
x3::double\u>>x3::double\u,
x3::空间,
d1,d2);//不起作用。只接受1个属性
它返回以下错误:
/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);
^
/home/sacha/Dev/vql/vqlcompiler.cpp:20:erreur:没有匹配函数用于调用“短语解析(uu gnu cxx::u normal_迭代器&,u gnu cxx::u normal_迭代器&,boost::spirit::x3::序列,常量空间&,double&,double&)”
x3::double\u>>x3::double\ux3::space,d1,d2);
^
似乎这不是一个可变的模板。那么,是我还是文件 确实如此。在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);
};
演示
#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";
}
非常好的解决方案,另一个版本发布在这里:
Parsed: 3.2, 4.5