I need to check that the value of a parsed qi::uint_
is less than 256.
I stumbled across an SO post outlining the following syntax to run checks after a primitive type has been parsed (qi::double_
in this example).
raw [ double_ [_val = _1] ] [ _pass = !isnan_(_val) && px::size(_1)<=4 ]
Here, raw[...]
returns an iterator to the parsed qi::double_
value, and the final semantic action is used to "test" the resulting value.
Extrapolating from the previous example, I assumed I could check bounds using a similar approach.
raw [ uint_ [_val = _1] ] [ _pass = _val<=256 ]
Unfortunately, I get the following error.
boost.spirit.qi.bounds.cpp:51:105: error: invalid operands to binary expression ('const boost::spirit::_val_type'
(aka 'const actor<attribute<0> >') and 'int')
if (qi::parse(str.begin(), str.end(), qi::raw[qi::uint_[qi::_val = qi::_1]][qi::_pass = qi::_val<=256]).full)
~~~~~~~~^ ~~~
The documentation and examples are great for basic parsers, but it begins to taper off with more advanced topics; such as this.
How can I convert or extract the unsigned integer value from qi::_val
to test against 256?