• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Generator Directive Duplicating Attributes (duplicate[])</title>
5<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../../../index.html" title="Spirit 2.5.8">
8<link rel="up" href="../directive.html" title="Generator Directives">
9<link rel="prev" href="omit.html" title="Generator Directives Consuming Attributes (omit[] and skip[])">
10<link rel="next" href="columns.html" title="Generator Directive Separating Output Into Columns (columns[])">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="omit.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../directive.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="columns.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h5 class="title">
27<a name="spirit.karma.reference.directive.duplicate"></a><a class="link" href="duplicate.html" title="Generator Directive Duplicating Attributes (duplicate[])">Generator
28          Directive Duplicating Attributes (<code class="computeroutput"><span class="identifier">duplicate</span><span class="special">[]</span></code>)</a>
29</h5></div></div></div>
30<h6>
31<a name="spirit.karma.reference.directive.duplicate.h0"></a>
32            <span class="phrase"><a name="spirit.karma.reference.directive.duplicate.description"></a></span><a class="link" href="duplicate.html#spirit.karma.reference.directive.duplicate.description">Description</a>
33          </h6>
34<p>
35            The directive <code class="computeroutput"><span class="identifier">duplicate</span><span class="special">[]</span></code> duplicates its attribute to all elements
36            of the embedded generator if this is a sequence generator. Otherwise
37            it does nothing.
38          </p>
39<h6>
40<a name="spirit.karma.reference.directive.duplicate.h1"></a>
41            <span class="phrase"><a name="spirit.karma.reference.directive.duplicate.header"></a></span><a class="link" href="duplicate.html#spirit.karma.reference.directive.duplicate.header">Header</a>
42          </h6>
43<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/directive/duplicate.hpp&gt;</span>
44<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">karma_duplicate</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
45</pre>
46<p>
47            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
48          </p>
49<div class="informaltable"><table class="table">
50<colgroup><col></colgroup>
51<thead><tr><th>
52                    <p>
53                      Name
54                    </p>
55                  </th></tr></thead>
56<tbody><tr><td>
57                    <p>
58                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">duplicate</span> <span class="comment">//
59                      alias: boost::spirit::karma::duplicate</span></code>
60                    </p>
61                  </td></tr></tbody>
62</table></div>
63<h6>
64<a name="spirit.karma.reference.directive.duplicate.h2"></a>
65            <span class="phrase"><a name="spirit.karma.reference.directive.duplicate.model_of"></a></span><a class="link" href="duplicate.html#spirit.karma.reference.directive.duplicate.model_of">Model of</a>
66          </h6>
67<div class="blockquote"><blockquote class="blockquote"><p>
68              <a class="link" href="../generator_concepts/unarygenerator.html" title="UnaryGenerator"><code class="computeroutput"><span class="identifier">UnaryGenerator</span></code></a>
69            </p></blockquote></div>
70<div class="variablelist">
71<p class="title"><b>Notation</b></p>
72<dl class="variablelist">
73<dt><span class="term"><code class="computeroutput"><span class="identifier">a</span></code></span></dt>
74<dd><p>
75                  A generator object
76                </p></dd>
77<dt><span class="term"><code class="computeroutput"><span class="identifier">A</span></code></span></dt>
78<dd><p>
79                  Attribute type of generator <code class="computeroutput"><span class="identifier">a</span></code>
80                </p></dd>
81</dl>
82</div>
83<h6>
84<a name="spirit.karma.reference.directive.duplicate.h3"></a>
85            <span class="phrase"><a name="spirit.karma.reference.directive.duplicate.expression_semantics"></a></span><a class="link" href="duplicate.html#spirit.karma.reference.directive.duplicate.expression_semantics">Expression
86            Semantics</a>
87          </h6>
88<p>
89            Semantics of an expression is defined only where it differs from, or
90            is not defined in <a class="link" href="../generator_concepts/unarygenerator.html" title="UnaryGenerator"><code class="computeroutput"><span class="identifier">UnaryGenerator</span></code></a>.
91          </p>
92<div class="informaltable"><table class="table">
93<colgroup>
94<col>
95<col>
96</colgroup>
97<thead><tr>
98<th>
99                    <p>
100                      Expression
101                    </p>
102                  </th>
103<th>
104                    <p>
105                      Semantics
106                    </p>
107                  </th>
108</tr></thead>
109<tbody><tr>
110<td>
111                    <p>
112                      <code class="computeroutput"><span class="identifier">duplicate</span><span class="special">[</span><span class="identifier">a</span><span class="special">]</span></code>
113                    </p>
114                  </td>
115<td>
116                    <p>
117                      The <code class="computeroutput"><span class="identifier">duplicate</span></code>
118                      directive duplicates the supplied attribute for all elements
119                      of a embedded sequence generator. For all other types of embedded
120                      generators it has no effect. It succeeds as long as its embedded
121                      generator does not fail.
122                    </p>
123                  </td>
124</tr></tbody>
125</table></div>
126<h6>
127<a name="spirit.karma.reference.directive.duplicate.h4"></a>
128            <span class="phrase"><a name="spirit.karma.reference.directive.duplicate.attributes"></a></span><a class="link" href="duplicate.html#spirit.karma.reference.directive.duplicate.attributes">Attributes</a>
129          </h6>
130<p>
131            See <a class="link" href="../../quick_reference/compound_attribute_rules.html#spirit.karma.quick_reference.compound_attribute_rules.notation">Compound
132            Attribute Notation</a>.
133          </p>
134<div class="informaltable"><table class="table">
135<colgroup>
136<col>
137<col>
138</colgroup>
139<thead><tr>
140<th>
141                    <p>
142                      Expression
143                    </p>
144                  </th>
145<th>
146                    <p>
147                      Attribute
148                    </p>
149                  </th>
150</tr></thead>
151<tbody><tr>
152<td>
153                    <p>
154                      <code class="computeroutput"><span class="identifier">duplicate</span><span class="special">[</span><span class="identifier">a</span><span class="special">]</span></code>
155                    </p>
156                  </td>
157<td>
158                    <p>
159</p>
160<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span> <span class="special">--&gt;</span> <span class="identifier">duplicate</span><span class="special">[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">A</span>
161<span class="identifier">a</span><span class="special">:</span> <span class="identifier">tuple</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">,</span> <span class="identifier">A</span><span class="special">,</span> <span class="special">...&gt;</span> <span class="special">--&gt;</span> <span class="identifier">duplicate</span><span class="special">[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">A</span>
162<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="identifier">duplicate</span><span class="special">[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">Unused</span></pre>
163<p>
164                    </p>
165                  </td>
166</tr></tbody>
167</table></div>
168<p>
169            If the embedded generator of the <code class="computeroutput"><span class="identifier">duplicate</span><span class="special">[]</span></code> directive is a sequence it is expected
170            that all elements of this sequence expose either the same attribute type,
171            an compatible attribute type, or <code class="computeroutput"><span class="identifier">unused</span></code>.
172            In this case, the <code class="computeroutput"><span class="identifier">duplicate</span><span class="special">[]</span></code> directive exposes the attribute type
173            of its first element. The behavior of the <code class="computeroutput"><span class="identifier">duplicate</span><span class="special">[]</span></code> directive is undefined if the elements
174            of an embedded sequence do not expose the same attributes. Most likely,
175            the corresponding expression will not compile.
176          </p>
177<h6>
178<a name="spirit.karma.reference.directive.duplicate.h5"></a>
179            <span class="phrase"><a name="spirit.karma.reference.directive.duplicate.complexity"></a></span><a class="link" href="duplicate.html#spirit.karma.reference.directive.duplicate.complexity">Complexity</a>
180          </h6>
181<div class="blockquote"><blockquote class="blockquote"><p>
182              The overall complexity of the <code class="computeroutput"><span class="identifier">duplicate</span><span class="special">[]</span></code> directive depends on the complexity
183              of the embedded generator.
184            </p></blockquote></div>
185<h6>
186<a name="spirit.karma.reference.directive.duplicate.h6"></a>
187            <span class="phrase"><a name="spirit.karma.reference.directive.duplicate.example"></a></span><a class="link" href="duplicate.html#spirit.karma.reference.directive.duplicate.example">Example</a>
188          </h6>
189<div class="note"><table border="0" summary="Note">
190<tr>
191<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
192<th align="left">Note</th>
193</tr>
194<tr><td align="left" valign="top"><p>
195              The test harness for the example(s) below is presented in the <a class="link" href="../basics.html#spirit.karma.reference.basics.examples">Basics Examples</a>
196              section.
197            </p></td></tr>
198</table></div>
199<p>
200            Some includes:
201          </p>
202<p>
203</p>
204<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">karma</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
205<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">support_utree</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
206<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">phoenix_core</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
207<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">phoenix_operator</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
208<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fusion</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">std_pair</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
209<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
210<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;</span>
211</pre>
212<p>
213          </p>
214<p>
215            Some using declarations:
216          </p>
217<p>
218</p>
219<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">double_</span><span class="special">;</span>
220<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">duplicate</span><span class="special">;</span>
221<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">space</span><span class="special">;</span>
222</pre>
223<p>
224          </p>
225<p>
226            Basic usage of the <code class="computeroutput"><span class="identifier">duplicate</span></code>
227            generators:
228          </p>
229<p>
230</p>
231<pre class="programlisting"><span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">"2.02.0"</span><span class="special">,</span> <span class="identifier">duplicate</span><span class="special">[</span><span class="identifier">double_</span> <span class="special">&lt;&lt;</span> <span class="identifier">double_</span><span class="special">],</span> <span class="number">2.0</span><span class="special">);</span>
232<span class="identifier">test_generator_attr_delim</span><span class="special">(</span><span class="string">"2.0 2.0 "</span><span class="special">,</span> <span class="identifier">duplicate</span><span class="special">[</span><span class="identifier">double_</span> <span class="special">&lt;&lt;</span> <span class="identifier">double_</span><span class="special">],</span> <span class="identifier">space</span><span class="special">,</span> <span class="number">2.0</span><span class="special">);</span>
233</pre>
234<p>
235          </p>
236</div>
237<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
238<td align="left"></td>
239<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
240        Distributed under the Boost Software License, Version 1.0. (See accompanying
241        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
242      </p>
243</div></td>
244</tr></table>
245<hr>
246<div class="spirit-nav">
247<a accesskey="p" href="omit.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../directive.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="columns.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
248</div>
249</body>
250</html>
251