|  | Home | Libraries | People | FAQ | More | 
            All generator components (except the Alternative
            (|) generator) pass
            their generated output directly to the underlying output stream. If a
            generator fails halfway through, the output generated so far is not 'rolled
            back'. The buffering generator directive allows to avoid this unwanted
            output to be generated. It temporarily redirects the output produced
            by the embedded generator into a buffer. This buffer is flushed to the
            underlying stream only after the embedded generator succeeded, but is
            discarded otherwise.
          
// forwards to <boost/spirit/home/karma/directive/buffer.hpp> #include <boost/spirit/include/karma_buffer.hpp>
Also, see Include Structure.
| Name | 
|---|
| 
                       | 
Notation
aA generator object
A
                  Attribute type of generator a
                
            Semantics of an expression is defined only where it differs from, or
            is not defined in UnaryGenerator.
          
| Expression | Semantics | 
|---|---|
| 
                       | 
                      The embedded generator  | 
| ![[Tip]](../../../../images/tip.png) | Tip | 
|---|---|
| 
              If you want to make the buffered generator succeed regardless of the
              outcome of the embedded generator, simply wrap the  | 
See Compound Attribute Notation.
| Expression | Attribute | 
|---|---|
| 
                       | 
 a: A --> buffer[a]: A a: Unused --> buffer[a]: Unused 
 | 
The overall complexity of the buffering generator directive is defined by the complexity of its embedded generator. The complexity of the buffering directive generator itself is O(N), where N is the number of characters buffered.
| ![[Note]](../../../../images/note.png) | 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/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::buffer;
            Basic usage of a buffering generator directive. It shows how the partial
            output generated in the first example does not show up in the generated
            output as the plus generator fails (no data is available, see Plus
            (unary +)).
          
std::vector<double> v; // empty container test_generator_attr("", -buffer['[' << +double_ << ']'], v); v.push_back(1.0); // now, fill the container v.push_back(2.0); test_generator_attr("[1.02.0]", buffer['[' << +double_ << ']'], v);