...one of the most highly
regarded and expertly designed C++ library projects in the
world. — Herb Sutter and Andrei
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.
Semantics of an expression is defined only where it differs from, or
is not defined in
All failing iterations of the embedded generator will consume one element from the supplied attribute.
See Compound Attribute Notation.
a: A --> *a: vector<A> a: Unused --> *a: Unused
The table above uses
The Kleene star generator will execute its embedded generator once for each element in the provided container attribute as long as the embedded generator succeeds. On each iteration it will pass the next consecutive element from the container attribute to the embedded generator. Therefore the number of iterations will not be larger than the number of elements in the container passed as its attribute. An empty container will make the Kleene star generate no output at all.
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.
The simplest way to force a Kleene star to behave as if it did buffering
is to wrap it into a buffering directive (see
which will not generate any output in case of
a failing generator
will not generate any partial output from a generator
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.
The test harness for the example(s) below is presented in the Basics Examples section.
#include <boost/spirit/include/karma.hpp> #include <boost/spirit/include/support_utree.hpp> #include <boost/phoenix/core.hpp> #include <boost/phoenix/operator.hpp> #include <boost/fusion/include/std_pair.hpp> #include <boost/proto/deep_copy.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; v.push_back(1.0); v.push_back(2.0); v.push_back(3.0); test_generator_attr_delim("1.0 2.0 3.0 ", *double_, space, v);