...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
The family of lazy
components
allows to use a dynamically returned generator component for output generation.
It calls the provided function or function object at generate time using
its return value as the actual generator to produce the output.
// forwards to <boost/spirit/home/karma/auxiliary/lazy.hpp> #include <boost/spirit/include/karma_lazy.hpp>
Also, see Include Structure.
Name |
---|
|
Notation
fg
A function or function object that evaluates to a generator object
(an object exposing the Generator
). This function
will be invoked at generate time.
The signature of fg
is
expected to be
G f(Unused, Context)
where G
, the function's
return value, is the type of the generator to be invoked, and Context
is the generator's Context
type (The first argument is unused
to make the Context
the
second argument. This is done for uniformity with Semantic
Actions).
Semantics of an expression is defined only where it differs from, or
is not defined in Generator
.
Expression |
Semantics |
---|---|
|
The Boost.Phoenix
function object |
|
The function or function object will be invoked at generate
time. It is expected to return a generator instance (note this
version of |
Expression |
Attribute |
---|---|
|
The attribute type |
|
The attribute type |
The complexity of the lazy
component is determined by the complexity of the generator returned from
fg
.
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:
namespace karma = boost::spirit::karma; using boost::spirit::karma::_1; using boost::spirit::ascii::string; using boost::phoenix::val;
Basic usage of the lazy
generator:
test_generator_attr("abc", karma::lazy(val(string)), "abc"); test_generator("abc", karma::lazy(val(string))[_1 = "abc"]);