セマンティック アクションを追加すると、属性の互換性が失われる可能性があるようです。次の簡単な例は、期待どおりに動作し、コンパイルされます。
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
パーサーの 1 つに追加する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;
セマンティック アクションが属性の互換性を壊すのはなぜですか? また、追加のセマンティック アクションはそれをどのように「修正」しますか?