I'm trying to create a simple parser that takes one of two possible characters using boost::spirit::x3
. The problem is that x3::char_('#') | x3::char_('.')
seems to have an attribute of type boost::variant<char, ?>
. This means I have to use boost::get<char>
on the _attr
, whereas it should be directly convertible to a char
.
http://ciere.com/cppnow15/x3_docs/spirit/quick_reference/compound_attribute_rules.html, it says A | A -> A
If the commented out version of mapChars
is used then it's convertible to a char
, but not the |
.
I am on boost version 1.63.0 and on Linux. The code fails to compile on both g++ and clang++ with -std=c++14
.
What am I doing wrong?
#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';
}