2

を使用して、2 つの可能な文字のいずれかを取る単純なパーサーを作成しようとしていますboost::spirit::x3。問題はx3::char_('#') | x3::char_('.')、 type の属性を持っているように見えることですboost::variant<char, ?>。これは、 で使用する必要があることを意味しますboost::get<char>が、_attrに直接変換できる必要がありますchar

http://ciere.com/cppnow15/x3_docs/spirit/quick_reference/compound_attribute_rules.html、それは言うA | A -> A

のコメントアウトされたバージョンmapCharsが使用されている場合、 に変換できますcharが、 . には変換できません|

私はブースト バージョン 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';
}
4

2 に答える 2