2

似乎添加语义操作会破坏属性兼容性。以下简单示例按预期工作和编译:

auto pair_rule = x3::rule<class·pair_rule, std::pair<std::string, std::string>>()
    = x3::alnum >> '=' >> x3::alnum;
auto combined = pair_rule | x3::alnum;

pair_rule现在,当我向in添加语义操作时combined

auto action = [&](auto& ctx) {}; 
auto pair_rule = x3::rule<class pair_rule, std::pair<std::string, std::string>>()
    = x3::alnum >> '=' >> x3::alnum;
auto combined = pair_rule[action] | x3::alnum;

编译器抱怨移动不兼容的类型

boost_1_62_0/boost/spirit/home/x3/support/traits/move_to.hpp:62:18: note:   mismatched types ‘const std::pair<_T1, _T2>’ and ‘std::remove_reference<const char&>::type {aka const char}’
         dest = std::move(src);

alnum但是,当向 中的一个解析器添加另一个语义操作时pair_rule,代码会再次编译:

auto action = [&](auto& ctx) {}; 
auto pair_rule = x3::rule<class pair_rule, std::pair<std::string, std::string>>()
    = x3::alnum >> '=' >> x3::alnum[action];
auto combined = pair_rule[action] | x3::alnum;

为什么语义动作会破坏属性兼容性,附加语义动作如何“修复”它?

4

0 回答 0