| Home | Libraries | People | FAQ | More

##### Generator Directive Duplicating Attributes (`duplicate[]`)

###### Description

The directive `duplicate[]` duplicates its attribute to all elements of the embedded generator if this is a sequence generator. Otherwise it does nothing.

###### Header

    // forwards to <boost/spirit/home/karma/directive/duplicate.hpp>
    #include <boost/spirit/include/karma_duplicate.hpp>

Also, see Include Structure.

Name
`boost::spirit::duplicate // alias: boost::spirit::karma::duplicate`

###### Model of

> `UnaryGenerator`

Notation

`a`

  A generator object

`A`

  Attribute type of generator `a`

###### Expression Semantics

Semantics of an expression is defined only where it differs from, or is not defined in `UnaryGenerator`.

Expression | Semantics
--- | ---
`duplicate[a]` | The `duplicate` directive duplicates the supplied attribute for all elements of a embedded sequence generator. For all other types of embedded generators it has no effect. It succeeds as long as its embedded generator does not fail.

###### Attributes

See Compound Attribute Notation.

Expression | Attribute
--- | ---

`duplicate[a]`

    a: A --> duplicate[a]: A
    a: tuple<A, A, ...> --> duplicate[a]: A
    a: Unused --> duplicate[a]: Unused

If the embedded generator of the `duplicate[]` directive is a sequence it is expected that all elements of this sequence expose either the same attribute type, an compatible attribute type, or `unused`. In this case, the `duplicate[]` directive exposes the attribute type of its first element. The behavior of the `duplicate[]` directive is undefined if the elements of an embedded sequence do not expose the same attributes. Most likely, the corresponding expression will not compile.

###### Complexity

> The overall complexity of the `duplicate[]` directive depends on the complexity of the embedded generator.

###### Example

| 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::duplicate;
    using boost::spirit::karma::space;

Basic usage of the `duplicate` generators:

    test_generator_attr("2.02.0", duplicate[double_ << double_], 2.0);
    test_generator_attr_delim("2.0 2.0 ", duplicate[double_ << double_], space, 2.0);