As you might expect, the bool_generator
can generate output from boolean values. The bool_generator
generator can be used to generate output from ordinary primitive C/C++
bool values or user defined
boolean types if the type follows certain expression requirements (for
more information about the requirements, see below)).
The bool_generator is
a template class. Template parameters fine tune its behavior.

lit is reused by the
String Generators,
the Character Generators,
and the Numeric Generators. In general, a char generator is created
when you pass in a character, a string generator is created when you
pass in a string, and a numeric generator is created when you use a
numeric (boolean) literal.

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

Expression

Semantics

lit(b)

Generate the boolean literal b
using the default formatting (false
is generated as "false",
and true is generated
as "true").
This generator never fails (unless the underlying output stream
reports an error).

bool_

Generate the boolean value provided by a mandatory attribute
using the default formatting (false
is generated as "false",
and true is generated
as "true").
This generator never fails (unless the underlying output stream
reports an error).

bool_(b)

Generate the boolean value provided by the immediate literal
value the generator is initialized from using the default formatting
(false is generated
as "false",
and true is generated
as "true").
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.

true_

Generate "true".
If this generator has an associated attribute it succeeds only
if the attribute is true
as well (unless the underlying output stream reports an error).

false_

Generate "false".
If this generator has an associated attribute it succeeds only
if the attribute is false
as well (unless the underlying output stream reports an error).

All generators listed in the table above (except lit(num)) are predefined specializations of the
bool_generator<B,Policies>
basic boolean generator type described below. It is possible to directly
use this type to create boolean generators using a wide range of formatting
options.

Expression

Semantics

bool_generator<B,Policies>()

Generate the boolean of type B
provided by a mandatory attribute using the specified Policies This generator never
fails (unless the underlying output stream reports an error).

bool_generator<B,Policies>()(b)

Generate the boolean of type B
provided by the immediate literal value the generator is initialized
from, using the specified Policies.
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.

Note

All boolean generators properly respect the upper and lower directives.

bool, attribute
is optional, if it is supplied, the generator compares the
attribute with b
and succeeds only if both are equal, failing otherwise.

bool_generator<B,Policies>()

B, attribute
is mandatory (otherwise compilation will fail)

bool_generator<B,Policies>()(b)

B, attribute
is optional, if it is supplied, the generator compares the
attribute with b
and succeeds only if both are equal, failing otherwise.

Note

In addition to their usual attribute of type B
all listed generators accept an instance of a boost::optional<B> as well. If the boost::optional<> is initialized (holds a value)
the generators behave as if their attribute was an instance of B and emit the value stored in the
boost::optional<>.
Otherwise the generators will fail.

If special formatting of a boolean is needed, overload the policy class
bool_policies<B>
and use it as a template parameter to the bool_generator<> boolean generator. For instance:

structspecial_bool_policy:karma::bool_policies<>{template<typenameCharEncoding,typenameTag,typenameOutputIterator>staticboolgenerate_false(OutputIterator&sink,boolb){// we want to spell the names of false as eurt (true backwards)
returnstring_inserter<CharEncoding,Tag>::call(sink,"eurt");}};typedefkarma::bool_generator<special_bool_policy>backwards_bool_type;backwards_bool_typeconstbackwards_bool;karma::generate(sink,backwards_bool,true);// will output: true
karma::generate(sink,backwards_bool(false));// will output: uert

The template parameter B
should be the type to be formatted using the overloaded policy type.
At the same time B will
be used as the attribute type of the created real number generator. The
default for B is bool.

This is the main function used to generate the output for a
boolean. It is called by the boolean generator in order to
perform the conversion. In theory all of the work can be implemented
here, but the easiest way is to use existing functionality
provided by the type specified by the template parameter Inserter. The default implementation
of this functions is:

The template parameters CharEncoding
and Tag are
either of the type unused_type
or describe the character class and conversion to be applied
to any output possibly influenced by either the lower[]
or upper[]
directives.

The template parameters CharEncoding
and Tag are
either of the type unused_type
or describe the character class and conversion to be applied
to any output possibly influenced by either the lower[]
or upper[]
directives.