...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
The uint_generator
class
is the simplest among the members of the numerics package. The uint_generator
can generate unsigned
integers of arbitrary length and size. The uint_generator
generator can be used to generate ordinary primitive C/C++ integers or
even user defined scalars such as bigints (unlimited precision integers)
if the type follows certain expression requirements (for more information
about the requirements, see below)).
The uint_generator
is
a template class. Template parameters fine tune its behavior.
// forwards to <boost/spirit/home/karma/numeric/uint.hpp> #include <boost/spirit/include/karma_uint.hpp>
Also, see Include Structure.
Name 









Important  

The generators 
Note  


template < typename Num , unsigned Radix> struct uint_generator;
Parameter 
Description 
Default 


The numeric base type of the numeric generator. 


The radix base. This can be either 2: binary, 8: octal, 10: decimal and 16: hexadecimal. 
10 
Notation
num
Numeric literal, any unsigned integer value, or a Lazy
Argument that evaluates to an unsigned integer value of type
Num
Num
Type of num
: any
unsigned integer type, or in case of a Lazy
Argument, its return value
Radix
An integer literal specifying the required radix for the output conversion.
Valid values are 2
,
8
, 10
,
and 16
.
Semantics of an expression is defined only where it differs from, or
is not defined in PrimitiveGenerator
.
Expression 
Semantics 


Generate the unsigned integer literal 
ushort uint ulong ulong_long

Generate the unsigned integer provided by a mandatory attribute using the default formatting (radix is 10). This generator never fails (unless the underlying output stream reports an error). 
ushort(num) uint(num) ulong(num) ulong_long(num)

Generate the unsigned integer provided by the immediate literal value the generator is initialized from using the default formatting (radix is 10). If this generator has an associated attribute it succeeds only if the attribute is equal to the immediate literal (unless the underlying output stream reports an error). Otherwise this generator fails and does not generate any output. 
bin oct hex

Generate the unsigned integer provided by a mandatory attribute
using the default formatting and the corresponding radix ( 
bin(num) oct(num) hex(num)

Generate the unsigned integer provided by the immediate literal
value the generator is initialized from using the default formatting
and the corresponding radix ( 
All generators listed in the table above (except lit(num)
) are predefined specializations of the
uint_generator<Num, Radix>
basic unsigned integer number generator type described below. It is possible
to directly use this type to create unsigned integer generators using
a wide range of formatting options.
Expression 
Semantics 

uint_generator< Num, Radix >()

Generate the unsigned integer of type 
uint_generator< Num, Radix >()(num)

Generate the unsigned integer of type 
The following lists enumerate the requirements which must be met in order
to use a certain type Num
to instantiate and use a uint_generator<Num, Radix>
.
If boost::is_integral<Num>::value
is true
the type Num
must have
defined:
<
,
<=
, ==
,
!=
, >
,
and >=
+
,

, /
,
*
, and %
If boost::is_integral<Num>::value
is false
the type Num
must have
defined:
<
,
<=
, ==
,
!=
, >
,
and >=
+
,

, /
,
*
, and %
std::fmod
, std::pow
,
std::lround
, std::ltrunc
,
std::floor
, and std::ceil
.
These need to be defined in a way so that they will be found using
argument dependent lookup (ADL).
Expression 
Attribute 



















bin oct hex


bin(num) oct(num) hex(num)


uint_generator< Num, Radix >()


uint_generator< Num, Radix >()(num)


Note  

In addition to their usual attribute of type 
O(N), where
N
is the number of digits needed to represent the generated integer number
Note  

The test harness for the example(s) below is presented in the Basics Examples section. 
Some includes:
#include <boost/spirit/include/karma.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/fusion/include/std_pair.hpp> #include <iostream> #include <string>
Some using declarations:
using boost::spirit::karma::uint_; using boost::spirit::karma::lit;
Basic usage of an uint
generator:
test_generator("2", lit(2U)); test_generator("2", uint_(2)); test_generator_attr("2", uint_(2), 2); test_generator_attr("", uint_(2), 3); // fails (as 2 != 3)! test_generator_attr("2", uint_, 2);