• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Signed Integer Number Generators (int_, etc.)</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="../numeric.html" title="Numeric Generators">
9<link rel="prev" href="unsigned_int.html" title="Unsigned Integer Number Generators (uint_, etc.)">
10<link rel="next" href="real_number.html" title="Real Number Generators (float_, double_, etc.)">
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="unsigned_int.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../numeric.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="real_number.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.numeric.signed_int"></a><a class="link" href="signed_int.html" title="Signed Integer Number Generators (int_, etc.)">Signed
28          Integer Number Generators (<code class="computeroutput"><span class="identifier">int_</span></code>,
29          etc.)</a>
30</h5></div></div></div>
31<h6>
32<a name="spirit.karma.reference.numeric.signed_int.h0"></a>
33            <span class="phrase"><a name="spirit.karma.reference.numeric.signed_int.description"></a></span><a class="link" href="signed_int.html#spirit.karma.reference.numeric.signed_int.description">Description</a>
34          </h6>
35<p>
36            The <code class="computeroutput"><span class="identifier">int_generator</span></code> can
37            generate signed integers of arbitrary length and size. This is almost
38            the same as the <code class="computeroutput"><span class="identifier">uint_generator</span></code>.
39            The only difference is the additional task of generating the <code class="computeroutput"><span class="char">'+'</span></code> or <code class="computeroutput"><span class="char">'-'</span></code>
40            sign preceding the number. The class interface is the same as that of
41            the <code class="computeroutput"><span class="identifier">uint_generator</span></code>.
42          </p>
43<p>
44            The <code class="computeroutput"><span class="identifier">int_generator</span></code> generator
45            can be used to emit ordinary primitive C/C++ integers or even user defined
46            scalars such as bigints (unlimited precision integers) if the type follows
47            certain expression requirements (for more information about the requirements,
48            see <a class="link" href="signed_int.html#spirit.karma.reference.numeric.signed_int.additional_requirements">below</a>).
49          </p>
50<h6>
51<a name="spirit.karma.reference.numeric.signed_int.h1"></a>
52            <span class="phrase"><a name="spirit.karma.reference.numeric.signed_int.header"></a></span><a class="link" href="signed_int.html#spirit.karma.reference.numeric.signed_int.header">Header</a>
53          </h6>
54<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/numeric/int.hpp&gt;</span>
55<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_int</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
56</pre>
57<p>
58            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
59          </p>
60<h6>
61<a name="spirit.karma.reference.numeric.signed_int.h2"></a>
62            <span class="phrase"><a name="spirit.karma.reference.numeric.signed_int.namespace"></a></span><a class="link" href="signed_int.html#spirit.karma.reference.numeric.signed_int.namespace">Namespace</a>
63          </h6>
64<div class="informaltable"><table class="table">
65<colgroup><col></colgroup>
66<thead><tr><th>
67                    <p>
68                      Name
69                    </p>
70                  </th></tr></thead>
71<tbody>
72<tr><td>
73                    <p>
74                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">lit</span> <span class="comment">// alias:
75                      boost::spirit::karma::lit</span></code>
76                    </p>
77                  </td></tr>
78<tr><td>
79                    <p>
80                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">short_</span> <span class="comment">//
81                      alias: boost::spirit::karma::short_</span></code>
82                    </p>
83                  </td></tr>
84<tr><td>
85                    <p>
86                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">int_</span> <span class="comment">// alias:
87                      boost::spirit::karma::int_</span></code>
88                    </p>
89                  </td></tr>
90<tr><td>
91                    <p>
92                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">long_</span> <span class="comment">//
93                      alias: boost::spirit::karma::long_</span></code>
94                    </p>
95                  </td></tr>
96<tr><td>
97                    <p>
98                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">long_long</span> <span class="comment">//
99                      alias: boost::spirit::karma::long_long</span></code>
100                    </p>
101                  </td></tr>
102</tbody>
103</table></div>
104<div class="note"><table border="0" summary="Note">
105<tr>
106<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
107<th align="left">Note</th>
108</tr>
109<tr><td align="left" valign="top"><p>
110              The generators <code class="computeroutput"><span class="identifier">long_long</span></code>
111              and <code class="computeroutput"><span class="identifier">long_long</span><span class="special">(</span><span class="identifier">num</span><span class="special">)</span></code>
112              are only available on platforms where the preprocessor constant <code class="computeroutput"><span class="identifier">BOOST_HAS_LONG_LONG</span></code> is defined (i.e.
113              on platforms having native support for <code class="computeroutput"><span class="keyword">long</span>
114              <span class="keyword">long</span></code> (64 bit) integer types).
115            </p></td></tr>
116</table></div>
117<div class="note"><table border="0" summary="Note">
118<tr>
119<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
120<th align="left">Note</th>
121</tr>
122<tr><td align="left" valign="top"><p>
123              <code class="computeroutput"><span class="identifier">lit</span></code> is reused by the
124              <a class="link" href="../string.html" title="String Generators">String Generators</a>,
125              the <a class="link" href="../char.html" title="Char Generators">Character Generators</a>,
126              and the Numeric Generators. In general, a char generator is created
127              when you pass in a character, a string generator is created when you
128              pass in a string, and a numeric generator is created when you use a
129              numeric literal.
130            </p></td></tr>
131</table></div>
132<h6>
133<a name="spirit.karma.reference.numeric.signed_int.h3"></a>
134            <span class="phrase"><a name="spirit.karma.reference.numeric.signed_int.synopsis"></a></span><a class="link" href="signed_int.html#spirit.karma.reference.numeric.signed_int.synopsis">Synopsis</a>
135          </h6>
136<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span>
137    <span class="keyword">typename</span> <span class="identifier">T</span>
138  <span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">Radix</span>
139  <span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">force_sign</span><span class="special">&gt;</span>
140<span class="keyword">struct</span> <span class="identifier">int_generator</span><span class="special">;</span>
141</pre>
142<h6>
143<a name="spirit.karma.reference.numeric.signed_int.h4"></a>
144            <span class="phrase"><a name="spirit.karma.reference.numeric.signed_int.template_parameters"></a></span><a class="link" href="signed_int.html#spirit.karma.reference.numeric.signed_int.template_parameters">Template
145            parameters</a>
146          </h6>
147<div class="informaltable"><table class="table">
148<colgroup>
149<col>
150<col>
151<col>
152</colgroup>
153<thead><tr>
154<th>
155                    <p>
156                      Parameter
157                    </p>
158                  </th>
159<th>
160                    <p>
161                      Description
162                    </p>
163                  </th>
164<th>
165                    <p>
166                      Default
167                    </p>
168                  </th>
169</tr></thead>
170<tbody>
171<tr>
172<td>
173                    <p>
174                      <code class="computeroutput"><span class="identifier">T</span></code>
175                    </p>
176                  </td>
177<td>
178                    <p>
179                      The numeric base type of the numeric parser.
180                    </p>
181                  </td>
182<td>
183                    <p>
184                      <code class="computeroutput"><span class="keyword">int</span></code>
185                    </p>
186                  </td>
187</tr>
188<tr>
189<td>
190                    <p>
191                      <code class="computeroutput"><span class="identifier">Radix</span></code>
192                    </p>
193                  </td>
194<td>
195                    <p>
196                      The radix base. This can be either 2: binary, 8: octal, 10:
197                      decimal and 16: hexadecimal.
198                    </p>
199                  </td>
200<td>
201                    <p>
202                      <code class="computeroutput"><span class="number">10</span></code>
203                    </p>
204                  </td>
205</tr>
206<tr>
207<td>
208                    <p>
209                      <code class="computeroutput"><span class="identifier">force_sign</span></code>
210                    </p>
211                  </td>
212<td>
213                    <p>
214                      If <code class="computeroutput"><span class="keyword">true</span></code>, all numbers
215                      will have a sign (space for zero)
216                    </p>
217                  </td>
218<td>
219                    <p>
220                      <code class="computeroutput"><span class="keyword">false</span></code>
221                    </p>
222                  </td>
223</tr>
224</tbody>
225</table></div>
226<h6>
227<a name="spirit.karma.reference.numeric.signed_int.h5"></a>
228            <span class="phrase"><a name="spirit.karma.reference.numeric.signed_int.model_of"></a></span><a class="link" href="signed_int.html#spirit.karma.reference.numeric.signed_int.model_of">Model of</a>
229          </h6>
230<div class="blockquote"><blockquote class="blockquote"><p>
231              <a class="link" href="../generator_concepts/primitivegenerator.html" title="PrimitiveGenerator"><code class="computeroutput"><span class="identifier">PrimitiveGenerator</span></code></a>
232            </p></blockquote></div>
233<div class="variablelist">
234<p class="title"><b>Notation</b></p>
235<dl class="variablelist">
236<dt><span class="term"><code class="computeroutput"><span class="identifier">num</span></code></span></dt>
237<dd><p>
238                  Numeric literal, any signed integer value, or a <a class="link" href="../basics.html#spirit.karma.reference.basics.lazy_argument">Lazy
239                  Argument</a> that evaluates to a signed integer value of type
240                  <code class="computeroutput"><span class="identifier">Num</span></code>
241                </p></dd>
242<dt><span class="term"><code class="computeroutput"><span class="identifier">Num</span></code></span></dt>
243<dd><p>
244                  Type of <code class="computeroutput"><span class="identifier">num</span></code>: any
245                  signed integer type
246                </p></dd>
247<dt><span class="term"><code class="computeroutput"><span class="identifier">Radix</span></code></span></dt>
248<dd><p>
249                  A constant integer literal specifying the required radix for the
250                  output conversion. Valid values are <code class="computeroutput"><span class="number">2</span></code>,
251                  <code class="computeroutput"><span class="number">8</span></code>, <code class="computeroutput"><span class="number">10</span></code>,
252                  and <code class="computeroutput"><span class="number">16</span></code>.
253                </p></dd>
254<dt><span class="term"><code class="computeroutput"><span class="identifier">force_sign</span></code></span></dt>
255<dd><p>
256                  A constant boolean literal specifying whether the generated number
257                  should always have a sign (<code class="computeroutput"><span class="char">'+'</span></code>
258                  for positive numbers, <code class="computeroutput"><span class="char">'-'</span></code>
259                  for negative numbers and a '<code class="computeroutput"> </code>' for zero).
260                </p></dd>
261</dl>
262</div>
263<h6>
264<a name="spirit.karma.reference.numeric.signed_int.h6"></a>
265            <span class="phrase"><a name="spirit.karma.reference.numeric.signed_int.expression_semantics"></a></span><a class="link" href="signed_int.html#spirit.karma.reference.numeric.signed_int.expression_semantics">Expression
266            Semantics</a>
267          </h6>
268<p>
269            Semantics of an expression is defined only where it differs from, or
270            is not defined in <a class="link" href="../generator_concepts/primitivegenerator.html" title="PrimitiveGenerator"><code class="computeroutput"><span class="identifier">PrimitiveGenerator</span></code></a>.
271          </p>
272<div class="informaltable"><table class="table">
273<colgroup>
274<col>
275<col>
276</colgroup>
277<thead><tr>
278<th>
279                    <p>
280                      Expression
281                    </p>
282                  </th>
283<th>
284                    <p>
285                      Semantics
286                    </p>
287                  </th>
288</tr></thead>
289<tbody>
290<tr>
291<td>
292                    <p>
293                      <code class="computeroutput"><span class="identifier">lit</span><span class="special">(</span><span class="identifier">num</span><span class="special">)</span></code>
294                    </p>
295                  </td>
296<td>
297                    <p>
298                      Generate the integer literal <code class="computeroutput"><span class="identifier">num</span></code>
299                      using the default formatting (radix is <code class="computeroutput"><span class="number">10</span></code>,
300                      sign is only printed for negative literals). This generator
301                      never fails (unless the underlying output stream reports an
302                      error).
303                    </p>
304                  </td>
305</tr>
306<tr>
307<td>
308                    <p>
309</p>
310<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">short_</span>
311<span class="identifier">int_</span>
312<span class="identifier">long_</span>
313<span class="identifier">long_long</span></pre>
314<p>
315                    </p>
316                  </td>
317<td>
318                    <p>
319                      Generate the integer provided by a mandatory attribute using
320                      the default formatting (radix is <code class="computeroutput"><span class="number">10</span></code>,
321                      sign is only printed for negative literals). This generator
322                      never fails (unless the underlying output stream reports an
323                      error).
324                    </p>
325                  </td>
326</tr>
327<tr>
328<td>
329                    <p>
330</p>
331<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">short_</span><span class="special">(</span><span class="identifier">num</span><span class="special">)</span>
332<span class="identifier">int_</span><span class="special">(</span><span class="identifier">num</span><span class="special">)</span>
333<span class="identifier">long_</span><span class="special">(</span><span class="identifier">num</span><span class="special">)</span>
334<span class="identifier">long_long</span><span class="special">(</span><span class="identifier">num</span><span class="special">)</span></pre>
335<p>
336                    </p>
337                  </td>
338<td>
339                    <p>
340                      Generate the integer provided by the immediate literal value
341                      the generator is initialized from using the default formatting
342                      (radix is <code class="computeroutput"><span class="number">10</span></code>, sign
343                      is only printed for negative literals). If this generator has
344                      an associated attribute it succeeds only if the attribute is
345                      equal to the immediate literal (unless the underlying output
346                      stream reports an error). Otherwise this generator fails and
347                      does not generate any output.
348                    </p>
349                  </td>
350</tr>
351</tbody>
352</table></div>
353<p>
354            All generators listed in the table above (except <code class="computeroutput"><span class="identifier">lit</span><span class="special">(</span><span class="identifier">num</span><span class="special">)</span></code>) are predefined specializations of the
355            <code class="computeroutput"><span class="identifier">int_generator</span><span class="special">&lt;</span><span class="identifier">Num</span><span class="special">,</span> <span class="identifier">Radix</span><span class="special">,</span> <span class="identifier">force_sign</span><span class="special">&gt;</span></code>
356            basic integer number generator type described below. It is possible to
357            directly use this type to create integer generators using a wide range
358            of formatting options.
359          </p>
360<div class="informaltable"><table class="table">
361<colgroup>
362<col>
363<col>
364</colgroup>
365<thead><tr>
366<th>
367                    <p>
368                      Expression
369                    </p>
370                  </th>
371<th>
372                    <p>
373                      Semantics
374                    </p>
375                  </th>
376</tr></thead>
377<tbody>
378<tr>
379<td>
380                    <p>
381</p>
382<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">int_generator</span><span class="special">&lt;</span>
383    <span class="identifier">Num</span><span class="special">,</span> <span class="identifier">Radix</span><span class="special">,</span> <span class="identifier">force_sign</span>
384<span class="special">&gt;()</span></pre>
385<p>
386                    </p>
387                  </td>
388<td>
389                    <p>
390                      Generate the integer of type <code class="computeroutput"><span class="identifier">Num</span></code>
391                      provided by a mandatory attribute using the specified <code class="computeroutput"><span class="identifier">Radix</span></code> (possible values are
392                      <code class="computeroutput"><span class="number">2</span></code>, <code class="computeroutput"><span class="number">8</span></code>, <code class="computeroutput"><span class="number">10</span></code>,
393                      and <code class="computeroutput"><span class="number">16</span></code>, the default
394                      value is <code class="computeroutput"><span class="number">10</span></code>). If
395                      <code class="computeroutput"><span class="identifier">force_sign</span></code>
396                      is <code class="computeroutput"><span class="keyword">false</span></code> (the
397                      default), a sign is only printed for negative literals. If
398                      <code class="computeroutput"><span class="identifier">force_sign</span></code>
399                      is <code class="computeroutput"><span class="keyword">true</span></code>, all numbers
400                      will be printed using a sign, i.e. <code class="computeroutput"><span class="char">'-'</span></code>
401                      for negative numbers, <code class="computeroutput"><span class="char">'+'</span></code>
402                      for positive numbers, and <code class="computeroutput"><span class="char">' '</span></code>
403                      for zeros. This generator never fails (unless the underlying
404                      output stream reports an error).
405                    </p>
406                  </td>
407</tr>
408<tr>
409<td>
410                    <p>
411</p>
412<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">int_generator</span><span class="special">&lt;</span>
413    <span class="identifier">Num</span><span class="special">,</span> <span class="identifier">Radix</span><span class="special">,</span> <span class="identifier">force_sign</span>
414<span class="special">&gt;()(</span><span class="identifier">num</span><span class="special">)</span></pre>
415<p>
416                    </p>
417                  </td>
418<td>
419                    <p>
420                      Generate the integer of type <code class="computeroutput"><span class="identifier">Num</span></code>
421                      provided by the immediate literal value the generator is initialized
422                      from, using the specified <code class="computeroutput"><span class="identifier">Radix</span></code>
423                      (possible values are <code class="computeroutput"><span class="number">2</span></code>,
424                      <code class="computeroutput"><span class="number">8</span></code>, <code class="computeroutput"><span class="number">10</span></code>, and <code class="computeroutput"><span class="number">16</span></code>,
425                      the default value is <code class="computeroutput"><span class="number">10</span></code>).
426                      If <code class="computeroutput"><span class="identifier">force_sign</span></code>
427                      is <code class="computeroutput"><span class="keyword">false</span></code> (the
428                      default), a sign is only printed for negative literals. If
429                      <code class="computeroutput"><span class="identifier">force_sign</span></code>
430                      is <code class="computeroutput"><span class="keyword">true</span></code>, all numbers
431                      will be printed using a sign, i.e. <code class="computeroutput"><span class="char">'-'</span></code>
432                      for negative numbers, <code class="computeroutput"><span class="char">'+'</span></code>
433                      for positive numbers, and <code class="computeroutput"><span class="char">' '</span></code>
434                      for zeros. If this generator has an associated attribute it
435                      succeeds only if the attribute is equal to the immediate literal
436                      (unless the underlying output stream reports an error). Otherwise
437                      this generator fails and does not generate any output.
438                    </p>
439                  </td>
440</tr>
441</tbody>
442</table></div>
443<h6>
444<a name="spirit.karma.reference.numeric.signed_int.h7"></a>
445            <span class="phrase"><a name="spirit.karma.reference.numeric.signed_int.additional_requirements"></a></span><a class="link" href="signed_int.html#spirit.karma.reference.numeric.signed_int.additional_requirements">Additional
446            Requirements</a>
447          </h6>
448<p>
449            The following lists enumerate the requirements which must be met in order
450            to use a certain type <code class="computeroutput"><span class="identifier">Num</span></code>
451            to instantiate and use a <code class="computeroutput"><span class="identifier">int_generator</span><span class="special">&lt;</span><span class="identifier">Num</span><span class="special">,</span> <span class="identifier">Radix</span><span class="special">,</span> <span class="identifier">force_sign</span><span class="special">&gt;</span></code>.
452          </p>
453<p>
454            If <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_integral</span><span class="special">&lt;</span><span class="identifier">Num</span><span class="special">&gt;::</span><span class="identifier">value</span></code> is <code class="computeroutput"><span class="keyword">true</span></code>
455            the type <code class="computeroutput"><span class="identifier">Num</span></code> must have
456            defined:
457          </p>
458<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
459<li class="listitem">
460                comparison operators for: <code class="computeroutput"><span class="special">&lt;</span></code>,
461                <code class="computeroutput"><span class="special">&lt;=</span></code>, <code class="computeroutput"><span class="special">==</span></code>, <code class="computeroutput"><span class="special">!=</span></code>,
462                <code class="computeroutput"><span class="special">&gt;</span></code>, and <code class="computeroutput"><span class="special">&gt;=</span></code>
463              </li>
464<li class="listitem">
465                numeric operators for: <code class="computeroutput"><span class="special">+</span></code>,
466                <code class="computeroutput"><span class="special">-</span></code>, <code class="computeroutput"><span class="special">/</span></code>,
467                <code class="computeroutput"><span class="special">*</span></code>, <code class="computeroutput"><span class="special">%</span></code>,
468                and unary <code class="computeroutput"><span class="special">-</span></code>
469              </li>
470</ul></div>
471<p>
472            If <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_integral</span><span class="special">&lt;</span><span class="identifier">Num</span><span class="special">&gt;::</span><span class="identifier">value</span></code> is <code class="computeroutput"><span class="keyword">false</span></code>
473            the type <code class="computeroutput"><span class="identifier">Num</span></code> must have
474            defined:
475          </p>
476<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
477<li class="listitem">
478                comparison operators for: <code class="computeroutput"><span class="special">&lt;</span></code>,
479                <code class="computeroutput"><span class="special">&lt;=</span></code>, <code class="computeroutput"><span class="special">==</span></code>, <code class="computeroutput"><span class="special">!=</span></code>,
480                <code class="computeroutput"><span class="special">&gt;</span></code>, and <code class="computeroutput"><span class="special">&gt;=</span></code>
481              </li>
482<li class="listitem">
483                numeric operators for: <code class="computeroutput"><span class="special">+</span></code>,
484                <code class="computeroutput"><span class="special">-</span></code>, <code class="computeroutput"><span class="special">/</span></code>,
485                <code class="computeroutput"><span class="special">*</span></code>, <code class="computeroutput"><span class="special">%</span></code>,
486                and unary <code class="computeroutput"><span class="special">-</span></code>
487              </li>
488<li class="listitem">
489                helper functions implementing the interface and the semantics of:
490                <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">fmod</span></code>, <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">fabs</span></code>,
491                <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pow</span></code>, <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">lround</span></code>,
492                <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ltrunc</span></code>, <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">floor</span></code>,
493                and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ceil</span></code>. These need to be defined
494                in a way so that they will be found using argument dependent lookup
495                (ADL).
496              </li>
497</ul></div>
498<h6>
499<a name="spirit.karma.reference.numeric.signed_int.h8"></a>
500            <span class="phrase"><a name="spirit.karma.reference.numeric.signed_int.attributes"></a></span><a class="link" href="signed_int.html#spirit.karma.reference.numeric.signed_int.attributes">Attributes</a>
501          </h6>
502<div class="informaltable"><table class="table">
503<colgroup>
504<col>
505<col>
506</colgroup>
507<thead><tr>
508<th>
509                    <p>
510                      Expression
511                    </p>
512                  </th>
513<th>
514                    <p>
515                      Attribute
516                    </p>
517                  </th>
518</tr></thead>
519<tbody>
520<tr>
521<td>
522                    <p>
523                      <code class="computeroutput"><span class="identifier">lit</span><span class="special">(</span><span class="identifier">num</span><span class="special">)</span></code>
524                    </p>
525                  </td>
526<td>
527                    <p>
528                      <code class="computeroutput"><span class="identifier">unused</span></code>
529                    </p>
530                  </td>
531</tr>
532<tr>
533<td>
534                    <p>
535                      <code class="computeroutput"><span class="identifier">short_</span></code>
536                    </p>
537                  </td>
538<td>
539                    <p>
540                      <code class="computeroutput"><span class="keyword">short</span></code>, attribute
541                      is mandatory (otherwise compilation will fail)
542                    </p>
543                  </td>
544</tr>
545<tr>
546<td>
547                    <p>
548                      <code class="computeroutput"><span class="identifier">short_</span><span class="special">(</span><span class="identifier">num</span><span class="special">)</span></code>
549                    </p>
550                  </td>
551<td>
552                    <p>
553                      <code class="computeroutput"><span class="keyword">short</span></code>, attribute
554                      is optional, if it is supplied, the generator compares the
555                      attribute with <code class="computeroutput"><span class="identifier">num</span></code>
556                      and succeeds only if both are equal, failing otherwise.
557                    </p>
558                  </td>
559</tr>
560<tr>
561<td>
562                    <p>
563                      <code class="computeroutput"><span class="identifier">int_</span></code>
564                    </p>
565                  </td>
566<td>
567                    <p>
568                      <code class="computeroutput"><span class="keyword">int</span></code>, attribute
569                      is mandatory (otherwise compilation will fail)
570                    </p>
571                  </td>
572</tr>
573<tr>
574<td>
575                    <p>
576                      <code class="computeroutput"><span class="identifier">int_</span><span class="special">(</span><span class="identifier">num</span><span class="special">)</span></code>
577                    </p>
578                  </td>
579<td>
580                    <p>
581                      <code class="computeroutput"><span class="keyword">int</span></code>, attribute
582                      is optional, if it is supplied, the generator compares the
583                      attribute with <code class="computeroutput"><span class="identifier">num</span></code>
584                      and succeeds only if both are equal, failing otherwise.
585                    </p>
586                  </td>
587</tr>
588<tr>
589<td>
590                    <p>
591                      <code class="computeroutput"><span class="identifier">long_</span></code>
592                    </p>
593                  </td>
594<td>
595                    <p>
596                      <code class="computeroutput"><span class="keyword">long</span></code>, attribute
597                      is mandatory (otherwise compilation will fail)
598                    </p>
599                  </td>
600</tr>
601<tr>
602<td>
603                    <p>
604                      <code class="computeroutput"><span class="identifier">long_</span><span class="special">(</span><span class="identifier">num</span><span class="special">)</span></code>
605                    </p>
606                  </td>
607<td>
608                    <p>
609                      <code class="computeroutput"><span class="keyword">long</span></code>, attribute
610                      is optional, if it is supplied, the generator compares the
611                      attribute with <code class="computeroutput"><span class="identifier">num</span></code>
612                      and succeeds only if both are equal, failing otherwise.
613                    </p>
614                  </td>
615</tr>
616<tr>
617<td>
618                    <p>
619                      <code class="computeroutput"><span class="identifier">long_long</span></code>
620                    </p>
621                  </td>
622<td>
623                    <p>
624                      <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">long</span></code>,
625                      attribute is mandatory (otherwise compilation will fail)
626                    </p>
627                  </td>
628</tr>
629<tr>
630<td>
631                    <p>
632                      <code class="computeroutput"><span class="identifier">long_long</span><span class="special">(</span><span class="identifier">num</span><span class="special">)</span></code>
633                    </p>
634                  </td>
635<td>
636                    <p>
637                      <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">long</span></code>,
638                      attribute is optional, if it is supplied, the generator compares
639                      the attribute with <code class="computeroutput"><span class="identifier">num</span></code>
640                      and succeeds only if both are equal, failing otherwise.
641                    </p>
642                  </td>
643</tr>
644<tr>
645<td>
646                    <p>
647</p>
648<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">int_generator</span><span class="special">&lt;</span>
649    <span class="identifier">Num</span><span class="special">,</span> <span class="identifier">Radix</span><span class="special">,</span> <span class="identifier">force_sign</span>
650<span class="special">&gt;()</span></pre>
651<p>
652                    </p>
653                  </td>
654<td>
655                    <p>
656                      <code class="computeroutput"><span class="identifier">Num</span></code>, attribute
657                      is mandatory (otherwise compilation will fail)
658                    </p>
659                  </td>
660</tr>
661<tr>
662<td>
663                    <p>
664</p>
665<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">int_generator</span><span class="special">&lt;</span>
666    <span class="identifier">Num</span><span class="special">,</span> <span class="identifier">Radix</span><span class="special">,</span> <span class="identifier">force_sign</span>
667<span class="special">&gt;()(</span><span class="identifier">num</span><span class="special">)</span></pre>
668<p>
669                    </p>
670                  </td>
671<td>
672                    <p>
673                      <code class="computeroutput"><span class="identifier">Num</span></code>, attribute
674                      is optional, if it is supplied, the generator compares the
675                      attribute with <code class="computeroutput"><span class="identifier">num</span></code>
676                      and succeeds only if both are equal, failing otherwise.
677                    </p>
678                  </td>
679</tr>
680</tbody>
681</table></div>
682<div class="note"><table border="0" summary="Note">
683<tr>
684<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
685<th align="left">Note</th>
686</tr>
687<tr><td align="left" valign="top"><p>
688              In addition to their usual attribute of type <code class="computeroutput"><span class="identifier">Num</span></code>
689              all listed generators accept an instance of a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">Num</span><span class="special">&gt;</span></code> as well. If the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special">&lt;&gt;</span></code> is initialized (holds a value)
690              the generators behave as if their attribute was an instance of <code class="computeroutput"><span class="identifier">Num</span></code> and emit the value stored in
691              the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special">&lt;&gt;</span></code>.
692              Otherwise the generators will fail.
693            </p></td></tr>
694</table></div>
695<h6>
696<a name="spirit.karma.reference.numeric.signed_int.h9"></a>
697            <span class="phrase"><a name="spirit.karma.reference.numeric.signed_int.complexity"></a></span><a class="link" href="signed_int.html#spirit.karma.reference.numeric.signed_int.complexity">Complexity</a>
698          </h6>
699<div class="blockquote"><blockquote class="blockquote"><p>
700              O(N), where <code class="computeroutput"><span class="identifier">N</span></code> is the
701              number of digits needed to represent the generated integer number
702            </p></blockquote></div>
703<h6>
704<a name="spirit.karma.reference.numeric.signed_int.h10"></a>
705            <span class="phrase"><a name="spirit.karma.reference.numeric.signed_int.example"></a></span><a class="link" href="signed_int.html#spirit.karma.reference.numeric.signed_int.example">Example</a>
706          </h6>
707<div class="note"><table border="0" summary="Note">
708<tr>
709<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
710<th align="left">Note</th>
711</tr>
712<tr><td align="left" valign="top"><p>
713              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>
714              section.
715            </p></td></tr>
716</table></div>
717<p>
718            Some includes:
719          </p>
720<p>
721</p>
722<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>
723<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>
724<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>
725<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>
726<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>
727<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
728<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;</span>
729</pre>
730<p>
731          </p>
732<p>
733            Some using declarations:
734          </p>
735<p>
736</p>
737<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">int_</span><span class="special">;</span>
738<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">lit</span><span class="special">;</span>
739</pre>
740<p>
741          </p>
742<p>
743            Basic usage of an <code class="computeroutput"><span class="identifier">int_</span></code>
744            generator:
745          </p>
746<p>
747</p>
748<pre class="programlisting"><span class="identifier">test_generator</span><span class="special">(</span><span class="string">"-2"</span><span class="special">,</span> <span class="identifier">lit</span><span class="special">(-</span><span class="number">2</span><span class="special">));</span>
749<span class="identifier">test_generator</span><span class="special">(</span><span class="string">"-2"</span><span class="special">,</span> <span class="identifier">int_</span><span class="special">(-</span><span class="number">2</span><span class="special">));</span>
750<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">"-2"</span><span class="special">,</span> <span class="identifier">int_</span><span class="special">(-</span><span class="number">2</span><span class="special">),</span> <span class="special">-</span><span class="number">2</span><span class="special">);</span>
751<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">""</span><span class="special">,</span> <span class="identifier">int_</span><span class="special">(-</span><span class="number">2</span><span class="special">),</span> <span class="number">3</span><span class="special">);</span>    <span class="comment">// fails (as -2 != 3)!</span>
752<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">"-2"</span><span class="special">,</span> <span class="identifier">int_</span><span class="special">,</span> <span class="special">-</span><span class="number">2</span><span class="special">);</span>
753</pre>
754<p>
755          </p>
756</div>
757<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
758<td align="left"></td>
759<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
760        Distributed under the Boost Software License, Version 1.0. (See accompanying
761        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>)
762      </p>
763</div></td>
764</tr></table>
765<hr>
766<div class="spirit-nav">
767<a accesskey="p" href="unsigned_int.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../numeric.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="real_number.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
768</div>
769</body>
770</html>
771