4

From testing I can get qi::uint_parser<int>() is the same as qi::uint_. They parse integers from 0 to UINT_MAX.

What I don't understand is that qi::uint_parser requires std::numeric_limits<T>::max() to be valid for the numeric base type T. I'm not sure if I should assume qi::uint_parser<int>() should parse integers from 0 to std::numeric_limits<int>::max() not std::numeric_limits<unsigned int>::max(). Or is this requirement has nothing to do with the parser's range?

wanghan02
  • 1,227
  • 7
  • 14

2 Answers2

0

I think this duplicates How to write a boost::spirit::qi parser to parse an integer range from 0 to std::numeric_limits<int>::max()? as well as the question I remember seeing on the mailing list.

Since it is apparently not documented, have you tested?

Or is this requirement has nothing to do with the parser's range?

I'd expect it to be the latter. I expect the attribute type says something about the attribute, not the parser. The parser parses, attribute propagation assigns to the attribute. Separation of concerns.

The attribute propagation is liable to do any implicit conversions that the C++ language will. This is actually no different from using unsigned in a scanf("%d") or reading an unsigned int using std::istream: See How to read unsigned int variables from file correctly, using ifstream?

I'd expect this all to be true because C++ combines the language core values of

  • pay only for what you need
  • the programmer knows what he's doing.

In fact, this is the root of the issue: Spirit defines qi::int_, qi::uint_ and friends. If you cobble up custom combinations using the underlying qi::[u]int_parser<> template, you're telling the compiler "I know what I'm doing".

DISCLAIMER: All of this is non-authoritative. I didn't even check the code/docs. I think it is essentially a documentation question which is better asked on the mailing list

sehe
  • 374,641
  • 47
  • 450
  • 633
  • 1
    What about this bit from the [docs](http://www.boost.org/doc/libs/1_62_0/libs/spirit/doc/html/spirit/qi/reference/numeric/uint.html)? "All numeric parsers check for overflow conditions based on the type T the corresponding uint_parser<> has been instantiated with. If the parsed number overflows this type the parsing fails. Please be aware that the overflow check is not based on the type of the supplied attribute but solely depends on the template parameter T." The way I read that is that T will affect the range it will parse. Am I reading it wrong? – Dan Mašek Dec 07 '16 at 23:32
-1

The problem is solved now on boost 1.68.0. qi::uint_parser<int>() parses integers from 0 to std::numeric_limits<int>::max(). spirit x3 is also fixed.

https://github.com/boostorg/spirit/pull/297

wanghan02
  • 1,227
  • 7
  • 14