【发布时间】:2013-06-20 16:01:36
【问题描述】:
尝试调整 boost spirit x3 calc 示例以解析可以将函数作为参数的函数。但是它不编译。
namespace client{ namespace ast{
struct ts;
struct fnc;
typedef boost::variant<
ts,
boost::recursive_wrapper<fnc>
> node;
struct ts{
unsigned int id;
};
struct fnc{
std::vector<char> id;
std::vector<node> args;
};
}}
BOOST_FUSION_ADAPT_STRUCT(
client::ast::ts,
(unsigned int, id)
)
BOOST_FUSION_ADAPT_STRUCT(
client::ast::fnc,
(std::vector<char>, id)
(std::vector<client::ast::node>, args)
)
namespace client{
namespace x3 = boost::spirit::x3;
namespace calc_grammar{
using x3::uint_;
using x3::alpha;
using x3::alnum;
using x3::lit;
using x3::char_;
x3::rule<class funct, ast::fnc> const funct("function");
x3::rule<class ts, ast::ts> const ts("timeseries");
x3::rule<class funct_name, std::vector<char>> const funct_name("function_name");
auto const funct_def = funct_name >> lit('(') >> -((ts|funct)%lit(',')) >> lit(')');
auto const ts_def = lit('#') >> uint_ >> lit('#');
auto const funct_name_def = lit('@') >> alpha >> *(alnum|char_('_'));
auto const calc = x3::grammar(
"calc",
funct = funct_def,
ts = ts_def,
funct_name = funct_name_def
);
}
using calc_grammar::calc;
}
错误 C2665: 'boost::detail::variant::make_initializer_node::apply::initializer_node::initialize': 5 个重载都不能转换所有参数类型
variant.hpp 中还有一条给用户的注释
// NOTE TO USER :
// Compile error here indicates that the given type is not
// unambiguously convertible to one of the variant's types
// (or that no conversion exists).
然而我并不聪明......
【问题讨论】:
-
在你得到更好的答案之前,添加一个什么都不做的默认构造函数和一个接受无符号整数并将其存储在
id中的构造函数到你的ts结构似乎使它对我有用g++ 4.8.1. -
@cv_and_he 完全同意分析; @user2515328 您可能想在
[spirit-general]用户列表中报告此问题 - 我认为开发人员正在积极征求反馈意见(boost-spirit.com 目前似乎已关闭) -
@cv_and_he 感谢您的提示,但仍然没有解决。使用 mvsc,我想我应该把它放在我最初的帖子中。
-
@not-sehe 我会试试的,我先把它放在这里,因为它看起来不那么令人生畏。
-
@user2515328 我同意:所以很甜蜜。但是,boost-spirit-x3 目前的受众非常有限,因此您在列表中的机会更大(您的反馈也将传达给感兴趣的开发者!)。干杯。 (顺便说一下,我创建了新标签)
标签: c++ visual-c++ boost-spirit boost-spirit-x3