• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Sequence Generator (a &lt;&lt; b)</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="../operator.html" title="Generator Operators">
9<link rel="prev" href="../operator.html" title="Generator Operators">
10<link rel="next" href="alternative.html" title="Alternative Generator (a | b)">
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="../operator.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../operator.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="alternative.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.operator.sequence"></a><a class="link" href="sequence.html" title="Sequence Generator (a &lt;&lt; b)">Sequence
28          Generator (<code class="computeroutput"><span class="identifier">a</span> <span class="special">&lt;&lt;</span>
29          <span class="identifier">b</span></code>)</a>
30</h5></div></div></div>
31<h6>
32<a name="spirit.karma.reference.operator.sequence.h0"></a>
33            <span class="phrase"><a name="spirit.karma.reference.operator.sequence.description"></a></span><a class="link" href="sequence.html#spirit.karma.reference.operator.sequence.description">Description</a>
34          </h6>
35<p>
36            Generator sequences are used to consecutively combine different, more
37            primitive generators. All generators in a sequence are invoked from left
38            to right as long as they succeed.
39          </p>
40<h6>
41<a name="spirit.karma.reference.operator.sequence.h1"></a>
42            <span class="phrase"><a name="spirit.karma.reference.operator.sequence.header"></a></span><a class="link" href="sequence.html#spirit.karma.reference.operator.sequence.header">Header</a>
43          </h6>
44<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/operator/sequence.hpp&gt;</span>
45<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_sequence</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
46</pre>
47<p>
48            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
49          </p>
50<h6>
51<a name="spirit.karma.reference.operator.sequence.h2"></a>
52            <span class="phrase"><a name="spirit.karma.reference.operator.sequence.model_of"></a></span><a class="link" href="sequence.html#spirit.karma.reference.operator.sequence.model_of">Model of</a>
53          </h6>
54<div class="blockquote"><blockquote class="blockquote"><p>
55              <a class="link" href="../generator_concepts/narygenerator.html" title="NaryGenerator"><code class="computeroutput"><span class="identifier">NaryGenerator</span></code></a>
56            </p></blockquote></div>
57<h6>
58<a name="spirit.karma.reference.operator.sequence.h3"></a>
59            <span class="phrase"><a name="spirit.karma.reference.operator.sequence.expression_semantics"></a></span><a class="link" href="sequence.html#spirit.karma.reference.operator.sequence.expression_semantics">Expression
60            Semantics</a>
61          </h6>
62<p>
63            Semantics of an expression is defined only where it differs from, or
64            is not defined in <a class="link" href="../generator_concepts/narygenerator.html" title="NaryGenerator"><code class="computeroutput"><span class="identifier">NaryGenerator</span></code></a>.
65          </p>
66<div class="informaltable"><table class="table">
67<colgroup>
68<col>
69<col>
70</colgroup>
71<thead><tr>
72<th>
73                    <p>
74                      Expression
75                    </p>
76                  </th>
77<th>
78                    <p>
79                      Semantics
80                    </p>
81                  </th>
82</tr></thead>
83<tbody><tr>
84<td>
85                    <p>
86                      <code class="computeroutput"><span class="identifier">a</span> <span class="special">&lt;&lt;</span>
87                      <span class="identifier">b</span></code>
88                    </p>
89                  </td>
90<td>
91                    <p>
92                      The generators <code class="computeroutput"><span class="identifier">a</span></code>
93                      and <code class="computeroutput"><span class="identifier">b</span></code> are executed
94                      sequentially from left to right and as long as they succeed.
95                      A failed generator stops the execution of the entire sequence
96                      and makes the sequence fail as well.
97                    </p>
98                  </td>
99</tr></tbody>
100</table></div>
101<p>
102            It is important to note, that sequences don't perform any buffering of
103            the output generated by its elements. That means that any failing sequence
104            might have already generated some output, which is <span class="emphasis"><em>not</em></span>
105            rolled back.
106          </p>
107<div class="tip"><table border="0" summary="Tip">
108<tr>
109<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../images/tip.png"></td>
110<th align="left">Tip</th>
111</tr>
112<tr><td align="left" valign="top">
113<p>
114              The simplest way to force a sequence to behave as if it did buffering
115              is to wrap it into a buffering directive (see <a class="link" href="../directive/buffer.html" title="Generator Directive for Temporary Output Buffering (buffer[])"><code class="computeroutput"><span class="identifier">buffer</span></code></a>):
116            </p>
117<p>
118</p>
119<pre class="programlisting"><span class="identifier">buffer</span><span class="special">[</span><span class="identifier">a</span> <span class="special">&lt;&lt;</span> <span class="identifier">b</span> <span class="special">&lt;&lt;</span> <span class="identifier">c</span><span class="special">]</span></pre>
120<p>
121            </p>
122<p>
123              which will <span class="emphasis"><em>not</em></span> generate any output in case of
124              a failing sequence.
125            </p>
126</td></tr>
127</table></div>
128<h6>
129<a name="spirit.karma.reference.operator.sequence.h4"></a>
130            <span class="phrase"><a name="spirit.karma.reference.operator.sequence.attributes"></a></span><a class="link" href="sequence.html#spirit.karma.reference.operator.sequence.attributes">Attributes</a>
131          </h6>
132<p>
133            See <a class="link" href="../../quick_reference/compound_attribute_rules.html#spirit.karma.quick_reference.compound_attribute_rules.notation">Compound
134            Attribute Notation</a>.
135          </p>
136<div class="informaltable"><table class="table">
137<colgroup>
138<col>
139<col>
140</colgroup>
141<thead><tr>
142<th>
143                    <p>
144                      Expression
145                    </p>
146                  </th>
147<th>
148                    <p>
149                      Attribute
150                    </p>
151                  </th>
152</tr></thead>
153<tbody><tr>
154<td>
155                    <p>
156                      <code class="computeroutput"><span class="identifier">a</span> <span class="special">&lt;&lt;</span>
157                      <span class="identifier">b</span></code> (sequence)
158                    </p>
159                  </td>
160<td>
161                    <p>
162</p>
163<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">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">B</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&lt;&lt;</span> <span class="identifier">b</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">B</span><span class="special">&gt;</span>
164<span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&lt;&lt;</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">A</span>
165<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">B</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&lt;&lt;</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">B</span>
166<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&lt;&lt;</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">Unused</span>
167
168<span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">A</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&lt;&lt;</span> <span class="identifier">b</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>
169<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> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">A</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&lt;&lt;</span> <span class="identifier">b</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>
170<span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span><span class="special">,</span> <span class="identifier">b</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> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&lt;&lt;</span> <span class="identifier">b</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>
171<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> <span class="identifier">b</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> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&lt;&lt;</span> <span class="identifier">b</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></pre>
172<p>
173                    </p>
174                  </td>
175</tr></tbody>
176</table></div>
177<div class="important"><table border="0" summary="Important">
178<tr>
179<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../images/important.png"></td>
180<th align="left">Important</th>
181</tr>
182<tr><td align="left" valign="top">
183<p>
184              The table above uses <code class="computeroutput"><span class="identifier">tuple</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">,</span> <span class="identifier">B</span><span class="special">&gt;</span></code> and <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.
185            </p>
186<p>
187              The notation <code class="computeroutput"><span class="identifier">tuple</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">,</span> <span class="identifier">B</span><span class="special">&gt;</span></code> stands for <span class="emphasis"><em>any fusion
188              sequence of two elements</em></span>, where <code class="computeroutput"><span class="identifier">A</span></code>
189              is the type of its first element and <code class="computeroutput"><span class="identifier">B</span></code>
190              is the type of its second element.
191            </p>
192<p>
193              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>
194              holding elements of type <code class="computeroutput"><span class="identifier">A</span></code>.
195            </p>
196</td></tr>
197</table></div>
198<p>
199            The attribute composition and propagation rules as shown in the table
200            above make sequences somewhat special as they can operate in two modes
201            if all elements have the same attribute type: consuming fusion sequences
202            and consuming STL containers. The selected mode depends on the type of
203            the attribute supplied.
204          </p>
205<h6>
206<a name="spirit.karma.reference.operator.sequence.h5"></a>
207            <span class="phrase"><a name="spirit.karma.reference.operator.sequence.complexity"></a></span><a class="link" href="sequence.html#spirit.karma.reference.operator.sequence.complexity">Complexity</a>
208          </h6>
209<div class="blockquote"><blockquote class="blockquote"><p>
210              The overall complexity of the sequence generator is defined by the
211              sum of the complexities of its elements. The complexity of the sequence
212              itself is O(N), where N is the number of elements in the sequence.
213            </p></blockquote></div>
214<h6>
215<a name="spirit.karma.reference.operator.sequence.h6"></a>
216            <span class="phrase"><a name="spirit.karma.reference.operator.sequence.example"></a></span><a class="link" href="sequence.html#spirit.karma.reference.operator.sequence.example">Example</a>
217          </h6>
218<div class="note"><table border="0" summary="Note">
219<tr>
220<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
221<th align="left">Note</th>
222</tr>
223<tr><td align="left" valign="top"><p>
224              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>
225              section.
226            </p></td></tr>
227</table></div>
228<p>
229            Some includes:
230          </p>
231<p>
232</p>
233<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>
234<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>
235<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>
236<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>
237<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>
238<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
239<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;</span>
240</pre>
241<p>
242          </p>
243<p>
244            Some using declarations:
245          </p>
246<p>
247</p>
248<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>
249</pre>
250<p>
251          </p>
252<p>
253            Basic usage of a sequence:
254          </p>
255<p>
256</p>
257<pre class="programlisting"><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">double_</span> <span class="special">&lt;&lt;</span> <span class="char">','</span> <span class="special">&lt;&lt;</span> <span class="identifier">double_</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">make_pair</span><span class="special">(</span><span class="number">1.0</span><span class="special">,</span> <span class="number">2.0</span><span class="special">));</span>
258</pre>
259<p>
260          </p>
261</div>
262<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
263<td align="left"></td>
264<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
265        Distributed under the Boost Software License, Version 1.0. (See accompanying
266        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>)
267      </p>
268</div></td>
269</tr></table>
270<hr>
271<div class="spirit-nav">
272<a accesskey="p" href="../operator.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../operator.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="alternative.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
273</div>
274</body>
275</html>
276