Home:ALL Converter>Why is x3::raw necessary here?

Why is x3::raw necessary here?

Ask Time:2021-10-19T22:09:53         Author:Matt

Json Formatter

The following code produces a large compiler error along the lines of static assertion failed: Size of the passed attribute is less than expected.:

constexpr x3::rule<struct Variable, ast::Variable> variable = "Variable";
const auto variable_def = +x3::alpha >> +x3::alnum;
BOOST_SPIRIT_DEFINE(variable);

where ast::Variable is defined as struct Variable { std::string name_; }.

However when surrounded by x3::raw[] it compiles fine:

const auto variable_def = x3::raw[+x3::alpha >> +x3::alnum];

I would expect for +x3::alpha >> +x3::alnum to collapse into a single std::string according to the compound attribute rule:

a: vector<A>, b: vector<A> --> (a >> b): vector<A>

especially since const auto variable_def = +x3::alpha; also compiles successfully.

Why is x3::raw[] necessary for +x3::alpha >> +x3::alnum?

Author:Matt,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69632410/why-is-x3raw-necessary-here
yy