That's it the title say it all.
In the context of boost spirit qi, I do not understand when attr_cast will be preferable over semantic action that converts the value, say: [_val = convert(_1)]
That's it the title say it all.
In the context of boost spirit qi, I do not understand when attr_cast will be preferable over semantic action that converts the value, say: [_val = convert(_1)]
Attr_cast can be useful to help spirit detect slightly incompatible attribute types (e.g. attr_cast<optional<bool>>
to change 'Just bool' into 'Maybe bool') and to define at which level attributes are going to be split, e.g.
string = '0' >> (repeat(3) [ qi::char_("0-9") ] % "'")
could have different attribute compatibility from
string = '0' >> attr_cast(repeat(3) [ qi::char_("0-9") ]) % "'"
See also:
In other words, I feel attr_cast
is not primarily useful to cast attribute values, but rather to annotate attribute types in sub-expressions with the "intended exposed attribute structure", without having to resort to declaring a qi::rule<>
to annotate that.
I only use attr_cast
as 'light-weight' rules.