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

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
Signed Integers (int_, etc.)
Description

The int_parser can parse signed integers of arbitrary length and size. This is almost the same as the uint_parser. The only difference is the additional task of parsing the '+' or '-' sign preceding the number. The class interface is the same as that of the uint_parser.

The int_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).

Header
// forwards to <boost/spirit/home/qi/numeric/int.hpp>
#include <boost/spirit/include/qi_int.hpp>

Also, see Include Structure.

Namespace

Name

boost::spirit::short_ // alias: boost::spirit::qi::short_

boost::spirit::int_ // alias: boost::spirit::qi::int_

boost::spirit::long_ // alias: boost::spirit::qi::long_

boost::spirit::long_long // alias: boost::spirit::qi::long_long

[Important] Important

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

Synopsis
template <
    typename T
  , unsigned Radix
  , unsigned MinDigits
  , int MaxDigits>
struct int_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 int_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 an int_parser

short_

Create an int_parser<short, 10, 1, -1>

long_

Create an int_parser<long, 10, 1, -1>

int_

Create an int_parser<int, 10, 1, -1>

long_long

Create an int_parser<long long, 10, 1, -1>

Attributes

T, The numeric base type of the numeric parser.

Complexity

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

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

Subtraction.

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::int_;

Basic signed integers:

test_parser("+12345", int_);
test_parser("-12345", int_);


PrevUpHomeNext