

Click here to view the latest version of this page.
Kleene Star Generator (*a)

Kleene star generators are used to repeat the execution of an embedded generator zero or more times. Regardless of the success of the embedded generator, the Kleene star generator always succeeds.

// forwards to <boost/spirit/home/karma/operator/kleene.hpp>
#include <boost/spirit/include/karma_kleene.hpp>

Also, see Include Structure.

Model of


Expression Semantics





The generator a is executed zero or more times depending on the availability of an attribute. The execution of a stops after the attribute values passed to the Kleene star generator are exhausted. The Kleene star always succeeds (unless the underlying output stream reports an error).

[Note] Note



See Compound Attribute Notation.



*a (Kleene star, unary *)

a: A --> *a: vector<A>
a: Unused --> *a: Unused

[Important] Important



It is important to note, that the Kleene star does not perform any buffering of the output generated by its embedded elements. That means that any failing element generator might have already generated some output, which is not rolled back.

[Tip] Tip

The simplest way to force a Kleene star to behave as if it did buffering is to wrap it into a buffering directive (see buffer):


which will not generate any output in case of a failing generator *a. The expression:




The overall complexity of the Kleene star generator is defined by the complexity of its embedded generator multiplied by the number of executed iterations. The complexity of the Kleene star itself is O(N), where N is the number of elements in the container passed as its attribute.

[Note] Note


Some includes:

#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/include/support_utree.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::double_;
using boost::spirit::karma::space;

Basic usage of a Kleene star generator:

std::vector<double> v;
test_generator_attr_delim("1.0 2.0 3.0 ", *double_, space, v);