boost::spirit::x3
を使用して2つの可能な文字のうちの1つを取る簡単なパーサーを作成しようとしています。問題は、x3::char_('#') | x3::char_('.')
の属性がboost::variant<char, ?>
であるようです。つまり、私はboost::get<char>
を_attr
に使用する必要がありますが、それは直接char
に変換する必要があります。boost spirit x3(A | A)の属性タイプは、Aの代わりに<A, ?>です
http://ciere.com/cppnow15/x3_docs/spirit/quick_reference/compound_attribute_rules.html、それはmapChars
のコメントアウトバージョンが使用されている場合、それは|
char
に変換可能だが、ないA | A -> A
を言います。
私はブーストバージョン1.63.0とLinuxで動作しています。コードは、g ++とclang ++の両方で、-std=c++14
でコンパイルできません。
私は間違っていますか?
#include <iostream>
#include <string>
#include <boost/spirit/home/x3.hpp>
int main() {
std::string s("#");
namespace x3 = boost::spirit::x3;
auto f = [](auto & ctx) {
auto & attr = x3::_attr(ctx);
//char c = attr; // doesn't work
char c = boost::get<char>(attr); // does work
};
auto mapChar = x3::char_('#') | x3::char_('.'); // _attr not convertible to char, is a variant
//auto mapChar = x3::char_('#'); // _attr convertible to char, isn't a variant
auto p = mapChar[f];
auto b = s.begin();
bool success = x3::parse(b, s.end(), p);
std::cout << "Success: " << success << ' ' << (b == s.end()) << '\n';
}
私は 'X3 ::文字_と思いますが、'あなたが欲しいものを行う必要があります。もちろん、これは 'A | A-> variant 'の問題を解決しません。 – llonesmiz
このサンプルでは、これは非常に相当のものです – sehe