| Home | Libraries | People | FAQ | More

##### API for Automatic Generator Creation

###### Description

The library implements a special API returning a generator instance for a supplied attribute type. This function finds the best matching generator type for the attribute based on a set of simple matching rules (as outlined in the table below) applied recursively to the attribute type. The returned generator can be utilized to emit output for the provided attribute.

###### Header

    // forwards to <boost/spirit/home/karma/auto.hpp>
    #include <boost/spirit/include/karma_auto.hpp>

Also, see Include Structure.

###### Namespace

Name
`boost::spirit::karma::create_generator`
`boost::spirit::traits::create_generator_exists`

###### Synopsis

    namespace boost { namespace spirit { namespace karma
    {
        template <typename Attr>
        inline <unspecified>
        create_generator();
    }}}

The returned instance can be directly passed as the generator (or the delimiting generator) to any of the Spirit.Karma API functions. Additionally it can be assigned to a rule as the rules right hand side expression. This function will return a valid generator type only if the meta function `traits::create_generator_exists` returns `mpl::true_`. Otherwise it will fail compiling.

    namespace boost { namespace spirit { namespace traits
    {
        template <typename Attr>
        struct create_generator_exists;
    }}}

The meta function evaluates to `mpl::true_` if `create_generator` would return a valid generator for the given type `Attr`.

The following table outlines the mapping rules from the attribute type to the generator type. These rules are applied recursively to create the generator type which can be used to generate output from the given attribute type.

Attribute type | Generator type
--- | ---
`char`, `wchar_t` | `standard::char_`, `standard_wide::char_`
`short`, `int`, `long` | `short_`, `int_`, `long_`
`unsigned short`, `unsigned int`, `unsigned long` | `ushort_`, `uint_`, `ulong_`
`float`, `double`, `long double` | `float_`, `double_`, `long_double`
`short`, `int`, `long` | `short_`, `int_`, `long_`
`long long`, `unsigned long long` | `long_long`, `ulong_long`
`bool` | `bool_`
Any string (`char const*`, `std::string`, etc.) | `string`
Any (STL) container | Kleene Star (unary `'*'`)
Any Fusion sequence | Sequence operator (`'<<'`)
`boost::optional<>` | Optional operator (unary `'-'`)
`boost::variant<>` | Alternative operator (`'|'`)

| Important
The mapping for the generators `long_long` and `ulong_long` are only available on platforms where the preprocessor constant `BOOST_HAS_LONG_LONG` is defined (i.e. on platforms having native support for `long long` and `unsigned long long` (64 bit) signed and unsigned integer types).

###### Template parameters

Parameter | Description
--- | ---
`Attr` | An attribute type utilized to create the corresponding generator type from.