• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Repetition Generator Directive (repeat[])</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="alignment.html" title="Alignment Generator Directives (left_align[], center[], right_align[])">
10<link rel="next" href="delimit.html" title="Generator Directives Controlling Automatic Delimiting (verbatim[], no_delimit[], delimit[])">
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="alignment.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="delimit.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.repeat"></a><a class="link" href="repeat.html" title="Repetition Generator Directive (repeat[])">Repetition
28          Generator Directive (<code class="computeroutput"><span class="identifier">repeat</span><span class="special">[]</span></code>)</a>
29</h5></div></div></div>
30<h6>
31<a name="spirit.karma.reference.directive.repeat.h0"></a>
32            <span class="phrase"><a name="spirit.karma.reference.directive.repeat.description"></a></span><a class="link" href="repeat.html#spirit.karma.reference.directive.repeat.description">Description</a>
33          </h6>
34<p>
35            The repetition directive allows to repeat an arbitrary generator expression
36            while optionally specifying the lower and upper repetition counts. It
37            provides a more powerful and flexible mechanism for repeating a generator.
38            There are grammars that are impractical and cumbersome, if not impossible,
39            for the basic EBNF iteration syntax ( <a class="link" href="../operator/kleene.html" title="Kleene Star Generator (*a)">unary
40            <code class="computeroutput"><span class="char">'*'</span></code></a> and the <a class="link" href="../operator/plus.html" title="Plus Generator (+a)">unary
41            <code class="computeroutput"><span class="char">'+'</span></code></a>) to specify. Examples:
42          </p>
43<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
44<li class="listitem">
45                A file name may have a maximum of 255 characters only.
46              </li>
47<li class="listitem">
48                A specific bitmap file format has exactly 4096 RGB color information.
49              </li>
50<li class="listitem">
51                A 256 bit binary string (1..256 1s or 0s).
52              </li>
53</ul></div>
54<h6>
55<a name="spirit.karma.reference.directive.repeat.h1"></a>
56            <span class="phrase"><a name="spirit.karma.reference.directive.repeat.header"></a></span><a class="link" href="repeat.html#spirit.karma.reference.directive.repeat.header">Header</a>
57          </h6>
58<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/directive/repeat.hpp&gt;</span>
59<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_repeat</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
60</pre>
61<p>
62            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
63          </p>
64<h6>
65<a name="spirit.karma.reference.directive.repeat.h2"></a>
66            <span class="phrase"><a name="spirit.karma.reference.directive.repeat.namespace"></a></span><a class="link" href="repeat.html#spirit.karma.reference.directive.repeat.namespace">Namespace</a>
67          </h6>
68<div class="informaltable"><table class="table">
69<colgroup><col></colgroup>
70<thead><tr><th>
71                    <p>
72                      Name
73                    </p>
74                  </th></tr></thead>
75<tbody>
76<tr><td>
77                    <p>
78                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">repeat</span> <span class="comment">//
79                      alias: boost::spirit::karma::repeat</span></code>
80                    </p>
81                  </td></tr>
82<tr><td>
83                    <p>
84                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">inf</span> <span class="comment">// alias:
85                      boost::spirit::karma::inf</span></code>
86                    </p>
87                  </td></tr>
88</tbody>
89</table></div>
90<h6>
91<a name="spirit.karma.reference.directive.repeat.h3"></a>
92            <span class="phrase"><a name="spirit.karma.reference.directive.repeat.model_of"></a></span><a class="link" href="repeat.html#spirit.karma.reference.directive.repeat.model_of">Model of</a>
93          </h6>
94<div class="blockquote"><blockquote class="blockquote"><p>
95              <a class="link" href="../generator_concepts/unarygenerator.html" title="UnaryGenerator"><code class="computeroutput"><span class="identifier">UnaryGenerator</span></code></a>
96            </p></blockquote></div>
97<div class="variablelist">
98<p class="title"><b>Notation</b></p>
99<dl class="variablelist">
100<dt><span class="term"><code class="computeroutput"><span class="identifier">a</span></code></span></dt>
101<dd><p>
102                  A generator object
103                </p></dd>
104<dt><span class="term"><code class="computeroutput"><span class="identifier">num</span><span class="special">,</span>
105              <span class="identifier">num1</span><span class="special">,</span>
106              <span class="identifier">num2</span></code></span></dt>
107<dd><p>
108                  Numeric literals, any unsigned integer value, or a <a class="link" href="../basics.html#spirit.karma.reference.basics.lazy_argument">Lazy
109                  Argument</a> that evaluates to an unsigned integer value
110                </p></dd>
111<dt><span class="term"><code class="computeroutput"><span class="identifier">inf</span></code></span></dt>
112<dd><p>
113                  Placeholder expression standing for 'no upper repeat limit'
114                </p></dd>
115</dl>
116</div>
117<h6>
118<a name="spirit.karma.reference.directive.repeat.h4"></a>
119            <span class="phrase"><a name="spirit.karma.reference.directive.repeat.expression_semantics"></a></span><a class="link" href="repeat.html#spirit.karma.reference.directive.repeat.expression_semantics">Expression
120            Semantics</a>
121          </h6>
122<p>
123            Semantics of an expression is defined only where it differs from, or
124            is not defined in <a class="link" href="../generator_concepts/unarygenerator.html" title="UnaryGenerator"><code class="computeroutput"><span class="identifier">UnaryGenerator</span></code></a>.
125          </p>
126<div class="informaltable"><table class="table">
127<colgroup>
128<col>
129<col>
130</colgroup>
131<thead><tr>
132<th>
133                    <p>
134                      Expression
135                    </p>
136                  </th>
137<th>
138                    <p>
139                      Semantics
140                    </p>
141                  </th>
142</tr></thead>
143<tbody>
144<tr>
145<td>
146                    <p>
147                      <code class="computeroutput"><span class="identifier">repeat</span><span class="special">[</span><span class="identifier">a</span><span class="special">]</span></code>
148                    </p>
149                  </td>
150<td>
151                    <p>
152                      Repeat the generator <code class="computeroutput"><span class="identifier">a</span></code>
153                      zero or more times. This generator succeeds as long as its
154                      embedded generator <code class="computeroutput"><span class="identifier">a</span></code>
155                      does not fail (except if the underlying output stream reports
156                      an error). This variant of <code class="computeroutput"><span class="identifier">repeat</span><span class="special">[]</span></code> is semantically equivalent
157                      to the <a class="link" href="../operator/kleene.html" title="Kleene Star Generator (*a)">Kleene
158                      Star operator <code class="computeroutput"><span class="special">*</span><span class="identifier">a</span></code></a>
159                    </p>
160                  </td>
161</tr>
162<tr>
163<td>
164                    <p>
165                      <code class="computeroutput"><span class="identifier">repeat</span><span class="special">(</span><span class="identifier">num</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code>
166                    </p>
167                  </td>
168<td>
169                    <p>
170                      Repeat the generator <code class="computeroutput"><span class="identifier">a</span></code>
171                      exactly <code class="computeroutput"><span class="identifier">num</span></code>
172                      times. This generator succeeds as long as its embedded generator
173                      <code class="computeroutput"><span class="identifier">a</span></code> does not
174                      fail and as long as the associated attribute (container) contains
175                      at least <code class="computeroutput"><span class="identifier">num</span></code>
176                      elements (unless the underlying output stream reports an error).
177                    </p>
178                  </td>
179</tr>
180<tr>
181<td>
182                    <p>
183                      <code class="computeroutput"><span class="identifier">repeat</span><span class="special">(</span><span class="identifier">num1</span><span class="special">,</span>
184                      <span class="identifier">num2</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code>
185                    </p>
186                  </td>
187<td>
188                    <p>
189                      Repeat the generator <code class="computeroutput"><span class="identifier">a</span></code>
190                      at least <code class="computeroutput"><span class="identifier">num1</span></code>
191                      times but not more than <code class="computeroutput"><span class="identifier">num2</span></code>
192                      times. This generator succeeds as long as its embedded generator
193                      <code class="computeroutput"><span class="identifier">a</span></code> does not
194                      fail and as long as the associated attribute (container) contains
195                      at least <code class="computeroutput"><span class="identifier">num1</span></code>
196                      elements (unless the underlying output stream reports an error).
197                      If the associated attribute (container) does contain more than
198                      <code class="computeroutput"><span class="identifier">num2</span></code> elements,
199                      this directive limits the repeat count to <code class="computeroutput"><span class="identifier">num2</span></code>.
200                    </p>
201                  </td>
202</tr>
203<tr>
204<td>
205                    <p>
206                      <code class="computeroutput"><span class="identifier">repeat</span><span class="special">(</span><span class="identifier">num</span><span class="special">,</span>
207                      <span class="identifier">inf</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code>
208                    </p>
209                  </td>
210<td>
211                    <p>
212                      Repeat the generator <code class="computeroutput"><span class="identifier">a</span></code>
213                      at least <code class="computeroutput"><span class="identifier">num1</span></code>
214                      times. No upper limit for the repeat count is set. This generator
215                      succeeds as long as its embedded generator <code class="computeroutput"><span class="identifier">a</span></code>
216                      does not fail and as long as the associated attribute (container)
217                      contains at least <code class="computeroutput"><span class="identifier">num</span></code>
218                      elements (unless the underlying output stream reports an error).
219                    </p>
220                  </td>
221</tr>
222</tbody>
223</table></div>
224<div class="note"><table border="0" summary="Note">
225<tr>
226<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
227<th align="left">Note</th>
228</tr>
229<tr><td align="left" valign="top"><p>
230              All failing iterations of the embedded generator will consume one element
231              from the supplied attribute. The overall <code class="computeroutput"><span class="identifier">repeat</span><span class="special">[</span><span class="identifier">a</span><span class="special">]</span></code> will succeed as long as the iteration
232              criteria (number of successful invocations of the embedded generator)
233              is fulfilled (unless the underlying output stream reports an error).
234            </p></td></tr>
235</table></div>
236<h6>
237<a name="spirit.karma.reference.directive.repeat.h5"></a>
238            <span class="phrase"><a name="spirit.karma.reference.directive.repeat.attributes"></a></span><a class="link" href="repeat.html#spirit.karma.reference.directive.repeat.attributes">Attributes</a>
239          </h6>
240<p>
241            See <a class="link" href="../../quick_reference/compound_attribute_rules.html#spirit.karma.quick_reference.compound_attribute_rules.notation">Compound
242            Attribute Notation</a>.
243          </p>
244<div class="informaltable"><table class="table">
245<colgroup>
246<col>
247<col>
248</colgroup>
249<thead><tr>
250<th>
251                    <p>
252                      Expression
253                    </p>
254                  </th>
255<th>
256                    <p>
257                      Attribute
258                    </p>
259                  </th>
260</tr></thead>
261<tbody>
262<tr>
263<td>
264                    <p>
265                      <code class="computeroutput"><span class="identifier">repeat</span><span class="special">[</span><span class="identifier">a</span><span class="special">]</span></code>
266                    </p>
267                  </td>
268<td>
269                    <p>
270</p>
271<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">repeat</span><span class="special">[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span>
272<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="identifier">repeat</span><span class="special">[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">Unused</span></pre>
273<p>
274                    </p>
275                  </td>
276</tr>
277<tr>
278<td>
279                    <p>
280                      <code class="computeroutput"><span class="identifier">repeat</span><span class="special">(</span><span class="identifier">num</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code>
281                    </p>
282                  </td>
283<td>
284                    <p>
285</p>
286<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">repeat</span><span class="special">(</span><span class="identifier">num</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span>
287<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="identifier">repeat</span><span class="special">(</span><span class="identifier">num</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">Unused</span></pre>
288<p>
289                    </p>
290                  </td>
291</tr>
292<tr>
293<td>
294                    <p>
295                      <code class="computeroutput"><span class="identifier">repeat</span><span class="special">(</span><span class="identifier">num1</span><span class="special">,</span>
296                      <span class="identifier">num2</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code>
297                    </p>
298                  </td>
299<td>
300                    <p>
301</p>
302<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">repeat</span><span class="special">(</span><span class="identifier">num1</span><span class="special">,</span> <span class="identifier">num2</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span>
303<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="identifier">repeat</span><span class="special">(</span><span class="identifier">num1</span><span class="special">,</span> <span class="identifier">num2</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">Unused</span></pre>
304<p>
305                    </p>
306                  </td>
307</tr>
308<tr>
309<td>
310                    <p>
311                      <code class="computeroutput"><span class="identifier">repeat</span><span class="special">(</span><span class="identifier">num</span><span class="special">,</span>
312                      <span class="identifier">inf</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code>
313                    </p>
314                  </td>
315<td>
316                    <p>
317</p>
318<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">repeat</span><span class="special">(</span><span class="identifier">num</span><span class="special">,</span> <span class="identifier">inf</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span>
319<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="identifier">repeat</span><span class="special">(</span><span class="identifier">num</span><span class="special">,</span> <span class="identifier">inf</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">Unused</span></pre>
320<p>
321                    </p>
322                  </td>
323</tr>
324</tbody>
325</table></div>
326<div class="important"><table border="0" summary="Important">
327<tr>
328<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../images/important.png"></td>
329<th align="left">Important</th>
330</tr>
331<tr><td align="left" valign="top">
332<p>
333              The table above uses <code class="computeroutput"><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span></code> as placeholders only.
334            </p>
335<p>
336              The notation of <code class="computeroutput"><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span></code> stands for <span class="emphasis"><em>any STL container</em></span>
337              holding elements of type <code class="computeroutput"><span class="identifier">A</span></code>.
338            </p>
339</td></tr>
340</table></div>
341<p>
342            It is important to note, that the <code class="computeroutput"><span class="identifier">repeat</span><span class="special">[]</span></code> directive does not perform any buffering
343            of the output generated by its embedded elements. That means that any
344            failing element generator might have already generated some output, which
345            is <span class="emphasis"><em>not</em></span> rolled back.
346          </p>
347<div class="tip"><table border="0" summary="Tip">
348<tr>
349<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../images/tip.png"></td>
350<th align="left">Tip</th>
351</tr>
352<tr><td align="left" valign="top">
353<p>
354              The simplest way to force a <code class="computeroutput"><span class="identifier">repeat</span><span class="special">[]</span></code> directive to behave as if it did
355              buffering is to wrap it into a buffering directive (see <a class="link" href="buffer.html" title="Generator Directive for Temporary Output Buffering (buffer[])"><code class="computeroutput"><span class="identifier">buffer</span></code></a>):
356            </p>
357<p>
358</p>
359<pre class="programlisting"><span class="identifier">buffer</span><span class="special">[</span><span class="identifier">repeat</span><span class="special">[</span><span class="identifier">a</span><span class="special">]]</span></pre>
360<p>
361            </p>
362<p>
363              which will <span class="emphasis"><em>not</em></span> generate any output in case of
364              a failing generator <code class="computeroutput"><span class="identifier">repeat</span><span class="special">[</span><span class="identifier">a</span><span class="special">]</span></code>. The expression:
365            </p>
366<p>
367</p>
368<pre class="programlisting"><span class="identifier">repeat</span><span class="special">[</span><span class="identifier">buffer</span><span class="special">[</span><span class="identifier">a</span><span class="special">]]</span></pre>
369<p>
370            </p>
371<p>
372              will not generate any partial output from a generator <code class="computeroutput"><span class="identifier">a</span></code> if it fails generating in the middle
373              of its output. The overall expression will still generate the output
374              as produced by all succeeded invocations of the generator <code class="computeroutput"><span class="identifier">a</span></code>.
375            </p>
376</td></tr>
377</table></div>
378<h6>
379<a name="spirit.karma.reference.directive.repeat.h6"></a>
380            <span class="phrase"><a name="spirit.karma.reference.directive.repeat.complexity"></a></span><a class="link" href="repeat.html#spirit.karma.reference.directive.repeat.complexity">Complexity</a>
381          </h6>
382<div class="blockquote"><blockquote class="blockquote"><p>
383              The overall complexity of the repetition generator is defined by the
384              complexity of its embedded generator. The complexity of the repeat
385              itself is O(N), where N is the number of repetitions to execute.
386            </p></blockquote></div>
387<h6>
388<a name="spirit.karma.reference.directive.repeat.h7"></a>
389            <span class="phrase"><a name="spirit.karma.reference.directive.repeat.example"></a></span><a class="link" href="repeat.html#spirit.karma.reference.directive.repeat.example">Example</a>
390          </h6>
391<div class="note"><table border="0" summary="Note">
392<tr>
393<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
394<th align="left">Note</th>
395</tr>
396<tr><td align="left" valign="top"><p>
397              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>
398              section.
399            </p></td></tr>
400</table></div>
401<p>
402            Some includes:
403          </p>
404<p>
405</p>
406<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>
407<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>
408<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>
409<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>
410<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>
411<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
412<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;</span>
413</pre>
414<p>
415          </p>
416<p>
417            Some using declarations:
418          </p>
419<p>
420</p>
421<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>
422<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">repeat</span><span class="special">;</span>
423</pre>
424<p>
425          </p>
426<p>
427            Basic usage of <code class="computeroutput"><span class="identifier">repeat</span></code>
428            generator directive:
429          </p>
430<p>
431</p>
432<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">v</span><span class="special">;</span>
433<span class="identifier">v</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="number">1.0</span><span class="special">);</span>
434<span class="identifier">v</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="number">2.0</span><span class="special">);</span>
435<span class="identifier">v</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="number">3.0</span><span class="special">);</span>
436
437<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">"[1.0][2.0][3.0]"</span><span class="special">,</span> <span class="identifier">repeat</span><span class="special">[</span><span class="char">'['</span> <span class="special">&lt;&lt;</span> <span class="identifier">double_</span> <span class="special">&lt;&lt;</span> <span class="char">']'</span><span class="special">],</span> <span class="identifier">v</span><span class="special">);</span>
438<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">"[1.0][2.0]"</span><span class="special">,</span> <span class="identifier">repeat</span><span class="special">(</span><span class="number">2</span><span class="special">)[</span><span class="char">'['</span> <span class="special">&lt;&lt;</span> <span class="identifier">double_</span> <span class="special">&lt;&lt;</span> <span class="char">']'</span><span class="special">],</span> <span class="identifier">v</span><span class="special">);</span>
439
440<span class="comment">// fails because of insufficient number of items</span>
441<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">""</span><span class="special">,</span> <span class="identifier">repeat</span><span class="special">(</span><span class="number">4</span><span class="special">)[</span><span class="char">'['</span> <span class="special">&lt;&lt;</span> <span class="identifier">double_</span> <span class="special">&lt;&lt;</span> <span class="char">']'</span><span class="special">],</span> <span class="identifier">v</span><span class="special">);</span>
442</pre>
443<p>
444          </p>
445</div>
446<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
447<td align="left"></td>
448<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
449        Distributed under the Boost Software License, Version 1.0. (See accompanying
450        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>)
451      </p>
452</div></td>
453</tr></table>
454<hr>
455<div class="spirit-nav">
456<a accesskey="p" href="alignment.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="delimit.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
457</div>
458</body>
459</html>
460