Closed syyyr closed 6 years ago
You want too much guessing from Spirit. It will not do collapsing because you want to parse sequence into tuple attribute (and size of the parser sequences do not match the size of the tuple attribute). To fix your code you need to add an intermediate rule which will do collapsing (and which result should be of std::vector
type). But as a general rule I will suggest you to not use single element tuples (you can simply replace ints_
with std::vector<int>
in your case, or with struct ints_ : std::vector<int> { };
if you need a "strong typedef").
If I add another
int
field to the struct, it successfully compiles
That extends your tuple type from tuple<vector<int>>
to tuple<vector<int>, int>
which is perfectly compatible with x3::int_ % '/' >> '*' >> x3::int_
parser.
It is not a bug in Spirit but a missing feature, and I do not think it is worth the complexity (refs https://github.com/boostorg/spirit/pull/178#issuecomment-198802189 and https://github.com/boostorg/spirit/issues/463).
Okay, so the root problem lies in that I use single element structures?
Okay, so the root problem lies in that I use single element structures?
Yes, quickfix is to replace
struct ints_ {
std::vector<int> m_vector;
};
BOOST_FUSION_ADAPT_STRUCT(ints_, m_vector)
with
struct ints_ : std::vector<int> {};
or even
typedef std::vector<int> ints_;
Okay, thank you.
Hello, I'm trying to make a rule, that parses integers separated by a slash, and the last one is separated by an asterisk:
Unfortunately, the code doesn't compile with this error:
According to the Compound Attribute Rules section in the documentation, the attribute of the
ints
rule should bevector<int>
:If I add another
int
field to the struct, it successfully compiles, but I would like to have all the integers in the same vector. Is there a solution to this? Am I not doing something right?