...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
The library provides a couple of free functions to make generating a
snap. These generator functions have two forms. The first form, generate
, concatenates the output generated
by the involved components without inserting any output in between. The
second generate_delimited
intersperses the output generated by the involved components using the
given delimiter generator. Both versions can take in attributes by (constant)
reference that hold the attribute values to output.
// forwards to <boost/spirit/home/karma/generate.hpp> #include <boost/spirit/include/karma_generate.hpp>
For variadic attributes:
// forwards to <boost/spirit/home/karma/generate_attr.hpp> #include <boost/spirit/include/karma_generate_attr.hpp>
The variadic attributes version of the API allows one or more attributes
to be passed into the generate
functions. The functions taking two or more attributes are usable when
the generator expression is a Sequence
(<<
) only.
In this case each of the attributes passed have to match the corresponding
part of the sequence.
For the API functions deducing the correct (matching) generator type from the supplied attribute type:
// forwards to <boost/spirit/home/karma/detail/generate_auto.hpp> #include <boost/spirit/include/karma_generate_auto.hpp>
Also, see Include Structure.
Name |
---|
|
|
|
|
namespace boost { namespace spirit { namespace karma { template <typename OutputIterator, typename Expr> inline bool generate( OutputIterator& sink , Expr const& expr); template <typename OutputIterator, typename Expr , typename Attr1, typename Attr2, ..., typename AttrN> inline bool generate( OutputIterator& sink , Expr const& expr , Attr1 const& attr1, Attr2 const& attr2, ..., AttrN const& attrN); template <typename OutputIterator, typename Expr, typename Delimiter> inline bool generate_delimited( OutputIterator& sink , Expr const& expr , Delimiter const& delimiter , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit = delimit_flag::dont_predelimit); template <typename OutputIterator, typename Expr, typename Delimiter , typename Attr1, typename Attr2, ..., typename AttrN> inline bool generate_delimited( OutputIterator& sink , Expr const& expr , Delimiter const& delimiter , Attr1 const& attr1, Attr2 const& attr2, ..., AttrN const& attrN); template <typename OutputIterator, typename Expr, typename Delimiter , typename Attr1, typename Attr2, ..., typename AttrN> inline bool generate_delimited( OutputIterator& sink , Expr const& expr , Delimiter const& delimiter , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit , Attr1 const& attr1, Attr2 const& attr2, ..., AttrN const& attrN); }}}
Note | |
---|---|
Starting with Spirit V2.5
(distributed with Boost V1.47) the placeholder |
Spirit.Karma generator API functions based on the automatic creation of the matching generator type:
namespace boost { namespace spirit { namespace karma { template <typename OutputIterator, typename Attr, typename Delimiter> inline bool generate_delimited( OutputIterator& sink , Attr const& attr , Delimiter const& delimiter , BOOST_SCOPED_ENUM(delimit_flag) pre_delimit = delimit_flag::dont_predelimit); template <typename OutputIterator, typename Attr> inline bool generate( OutputIterator& sink , Attr const& attr); }}}
All functions above return true
if none of the involved generator components failed, and false
otherwise. If during the process
of the output generation the underlying output stream reports an error,
the return value will be false
as well.
The maximum number of supported arguments is limited by the preprocessor
constant SPIRIT_ARGUMENTS_LIMIT
.
This constant defaults to the value defined by the preprocessor constant
PHOENIX_LIMIT
(which
in turn defaults to 10
).
Note | |
---|---|
The variadic functions with two or more attributes internally combine
(constant) references to all passed attributes into a |
The generate_delimited
functions not taking an explicit delimit_flag
as one of their arguments don't invoke the passed delimiter before starting
to generate output from the generator expression. This can be enabled
by using the other version of that function while passing delimit_flag::predelimit
to the corresponding argument.
Parameter |
Description |
---|---|
|
|
|
An expression that can be converted to a Karma generator. |
|
Generator used to delimit the output of the expression components. |
|
An attribute type utilized to create the corresponding generator type from. |
|
One or more attributes. |