Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Click here to view the latest version of this page.
PrevUpHomeNext
Unsigned Integers (uint_, etc.)
Description

The uint_parser class is the simplest among the members of the numerics package. The uint_parser can parse unsigned integers of arbitrary length and size. The uint_parser parser can be used to parse ordinary primitive C/C++ integers or even user defined scalars such as bigints (unlimited precision integers) as long as the type follows certain expression requirements (documented below). The uint_parser is a template class. Template parameters fine tune its behavior.

Header
// forwards to <boost/spirit/home/qi/numeric/uint.hpp>
#include <boost/spirit/include/qi_uint.hpp>

Also, see Include Structure.

Namespace

Name

boost::spirit::bin // alias: boost::spirit::qi::bin

boost::spirit::oct // alias: boost::spirit::qi::oct

boost::spirit::hex // alias: boost::spirit::qi::hex

boost::spirit::ushort_ // alias: boost::spirit::qi::ushort_

boost::spirit::ulong_ // alias: boost::spirit::qi::ulong_

boost::spirit::uint_ // alias: boost::spirit::qi::uint_

boost::spirit::ulong_long // alias: boost::spirit::qi::ulong_long

[Note] Note

ulong_long is only available on platforms where the preprocessor constant BOOST_HAS_LONG_LONG is defined (i.e. on platforms having native support for unsigned long long (64 bit) unsigned integer types).

Synopsis
template <
    typename T
  , unsigned Radix
  , unsigned MinDigits
  , int MaxDigits>
struct uint_parser;
Template parameters

Parameter

Description

Default

T

The numeric base type of the numeric parser.

none

Radix

The radix base. This can be either 2: binary, 8: octal, 10: decimal and 16: hexadecimal.

10

MinDigits

The minimum number of digits allowable.

1

MaxDigits

The maximum number of digits allowable. If this is -1, then the maximum limit becomes unbounded.

-1

Model of

PrimitiveParser

Notation

NP

An instance of uint_parser (type).

n

An object of T, the numeric base type.

Expression Semantics

Semantics of an expression is defined only where it differs from, or is not defined in PrimitiveParser.

Expression

Semantics

NP()

Instantiate and (default) construct a uint_parser

bin

Create a uint_parser<unsigned, 2, 1, -1>

oct

Create a uint_parser<unsigned, 8, 1, -1>

hex

Create a uint_parser<unsigned, 16, 1, -1>

ushort_

Create a uint_parser<unsigned short, 10, 1, -1>

ulong_

Create a uint_parser<unsigned long, 10, 1, -1>

uint_

Create a uint_parser<unsigned int, 10, 1, -1>

ulong_long

Create a uint_parser<unsigned long long, 10, 1, -1>

[Important] Important

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.

Attributes

T, The numeric base type of the numeric parser.

Complexity

O(N), where N is the number of digits being parsed.

Minimum Expression Requirements for T

For the numeric base type, T, the expression requirements below must be valid:

Expression

Semantics

T()

Default construct.

T(0)

Construct from an int.

n + n

Addition.

n * n

Multiplication.

std::numeric_limits<T>::is_bounded

true or false if T bounded.

std::numeric_limits<T>::digits

Maximum Digits for T, radix digits. Required only if T is bounded.

std::numeric_limits<T>::digits10

Maximum Digits for T, base 10. Required only if T is bounded.

std::numeric_limits<T>::max()

Maximum value for T. Required only if T is bounded.

std::numeric_limits<T>::min()

Minimum value for T. Required only if T is bounded.

Example
[Note] Note

The test harness for the example(s) below is presented in the Basics Examples section.

Some using declarations:

using boost::spirit::qi::uint_;
using boost::spirit::qi::uint_parser;

Basic unsigned integers:

test_parser("12345", uint_);

Thousand separated number parser:

uint_parser<unsigned, 10, 1, 3> uint3_p;        //  1..3 digits
uint_parser<unsigned, 10, 3, 3> uint3_3_p;      //  exactly 3 digits        
test_parser("12,345,678", uint3_p >> *(',' >> uint3_3_p));


PrevUpHomeNext