• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Boolean Parser (bool_)</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 Parsers">
9<link rel="prev" href="real.html" title="Real Number Parsers (float_, double_, etc.)">
10<link rel="next" href="../operator.html" title="Parser Operators">
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="real.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="../operator.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.qi.reference.numeric.boolean"></a><a class="link" href="boolean.html" title="Boolean Parser (bool_)">Boolean Parser
28          (<code class="computeroutput"><span class="identifier">bool_</span></code>)</a>
29</h5></div></div></div>
30<h6>
31<a name="spirit.qi.reference.numeric.boolean.h0"></a>
32            <span class="phrase"><a name="spirit.qi.reference.numeric.boolean.description"></a></span><a class="link" href="boolean.html#spirit.qi.reference.numeric.boolean.description">Description</a>
33          </h6>
34<p>
35            The <code class="computeroutput"><span class="identifier">bool_parser</span></code> can parse
36            booleans of arbitrary type, <code class="computeroutput"><span class="identifier">B</span></code>.
37            The boolean base type <code class="computeroutput"><span class="identifier">T</span></code>
38            can be a user defined boolean type as long as the type follows certain
39            expression requirements (documented below).
40          </p>
41<h6>
42<a name="spirit.qi.reference.numeric.boolean.h1"></a>
43            <span class="phrase"><a name="spirit.qi.reference.numeric.boolean.header"></a></span><a class="link" href="boolean.html#spirit.qi.reference.numeric.boolean.header">Header</a>
44          </h6>
45<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/qi/numeric/bool.hpp&gt;</span>
46<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">qi_bool</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
47</pre>
48<p>
49            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
50          </p>
51<h6>
52<a name="spirit.qi.reference.numeric.boolean.h2"></a>
53            <span class="phrase"><a name="spirit.qi.reference.numeric.boolean.namespace"></a></span><a class="link" href="boolean.html#spirit.qi.reference.numeric.boolean.namespace">Namespace</a>
54          </h6>
55<div class="informaltable"><table class="table">
56<colgroup><col></colgroup>
57<thead><tr><th>
58                    <p>
59                      Name
60                    </p>
61                  </th></tr></thead>
62<tbody>
63<tr><td>
64                    <p>
65                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">bool_</span> <span class="comment">//
66                      alias: boost::spirit::qi::bool_</span></code>
67                    </p>
68                  </td></tr>
69<tr><td>
70                    <p>
71                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">true_</span> <span class="comment">//
72                      alias: boost::spirit::qi::true_</span></code>
73                    </p>
74                  </td></tr>
75<tr><td>
76                    <p>
77                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">false_</span> <span class="comment">//
78                      alias: boost::spirit::qi::false_</span></code>
79                    </p>
80                  </td></tr>
81</tbody>
82</table></div>
83<h6>
84<a name="spirit.qi.reference.numeric.boolean.h3"></a>
85            <span class="phrase"><a name="spirit.qi.reference.numeric.boolean.synopsis"></a></span><a class="link" href="boolean.html#spirit.qi.reference.numeric.boolean.synopsis">Synopsis</a>
86          </h6>
87<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">BooleanPolicies</span><span class="special">&gt;</span>
88<span class="keyword">struct</span> <span class="identifier">bool_parser</span><span class="special">;</span>
89</pre>
90<h6>
91<a name="spirit.qi.reference.numeric.boolean.h4"></a>
92            <span class="phrase"><a name="spirit.qi.reference.numeric.boolean.template_parameters"></a></span><a class="link" href="boolean.html#spirit.qi.reference.numeric.boolean.template_parameters">Template
93            parameters</a>
94          </h6>
95<div class="informaltable"><table class="table">
96<colgroup>
97<col>
98<col>
99<col>
100</colgroup>
101<thead><tr>
102<th>
103                    <p>
104                      Parameter
105                    </p>
106                  </th>
107<th>
108                    <p>
109                      Description
110                    </p>
111                  </th>
112<th>
113                    <p>
114                      Default
115                    </p>
116                  </th>
117</tr></thead>
118<tbody>
119<tr>
120<td>
121                    <p>
122                      <code class="computeroutput"><span class="identifier">B</span></code>
123                    </p>
124                  </td>
125<td>
126                    <p>
127                      The boolean type of the boolean parser.
128                    </p>
129                  </td>
130<td>
131                    <p>
132                      <code class="computeroutput"><span class="keyword">bool</span></code>
133                    </p>
134                  </td>
135</tr>
136<tr>
137<td>
138                    <p>
139                      <code class="computeroutput"><span class="identifier">BooleanPolicies</span></code>
140                    </p>
141                  </td>
142<td>
143                    <p>
144                      Policies control the parser's behavior.
145                    </p>
146                  </td>
147<td>
148                    <p>
149                      <code class="computeroutput"><span class="identifier">bool_policies</span><span class="special">&lt;</span><span class="identifier">B</span><span class="special">&gt;</span></code>
150                    </p>
151                  </td>
152</tr>
153</tbody>
154</table></div>
155<h6>
156<a name="spirit.qi.reference.numeric.boolean.h5"></a>
157            <span class="phrase"><a name="spirit.qi.reference.numeric.boolean.model_of"></a></span><a class="link" href="boolean.html#spirit.qi.reference.numeric.boolean.model_of">Model
158            of</a>
159          </h6>
160<div class="blockquote"><blockquote class="blockquote"><p>
161              <a class="link" href="../parser_concepts/primitiveparser.html" title="PrimitiveParser"><code class="computeroutput"><span class="identifier">PrimitiveParser</span></code></a>
162            </p></blockquote></div>
163<div class="variablelist">
164<p class="title"><b>Notation</b></p>
165<dl class="variablelist">
166<dt><span class="term"><code class="computeroutput"><span class="identifier">BP</span></code></span></dt>
167<dd><p>
168                  A boolean <code class="computeroutput"><span class="identifier">Policies</span></code>
169                  (type).
170                </p></dd>
171<dt><span class="term"><code class="computeroutput"><span class="identifier">b</span></code></span></dt>
172<dd><p>
173                  An object of <code class="computeroutput"><span class="identifier">B</span></code>,
174                  the numeric base type.
175                </p></dd>
176<dt><span class="term"><code class="computeroutput"><span class="identifier">boolean</span></code></span></dt>
177<dd><p>
178                  Numeric literal, any boolean value, or a <a class="link" href="../basics.html#spirit.qi.reference.basics.lazy_argument">Lazy
179                  Argument</a> that evaluates to a boolean value.
180                </p></dd>
181<dt><span class="term"><code class="computeroutput"><span class="identifier">f</span></code>, <code class="computeroutput"><span class="identifier">l</span></code></span></dt>
182<dd><p>
183                  <a href="http://en.cppreference.com/w/cpp/named_req/ForwardIterator" target="_top"><code class="computeroutput"><span class="identifier">ForwardIterator</span></code></a>. first/last
184                  iterator pair.
185                </p></dd>
186<dt><span class="term"><code class="computeroutput"><span class="identifier">attr</span></code></span></dt>
187<dd><p>
188                  An attribute value.
189                </p></dd>
190<dt><span class="term"><code class="computeroutput"><span class="identifier">Context</span></code></span></dt>
191<dd><p>
192                  The type of the parse context of the current invocation of the
193                  <code class="computeroutput"><span class="identifier">bool_</span></code> parser.
194                </p></dd>
195<dt><span class="term"><code class="computeroutput"><span class="identifier">ctx</span></code></span></dt>
196<dd><p>
197                  An instance of the parse context, <code class="computeroutput"><span class="identifier">Context</span></code>.
198                </p></dd>
199</dl>
200</div>
201<h6>
202<a name="spirit.qi.reference.numeric.boolean.h6"></a>
203            <span class="phrase"><a name="spirit.qi.reference.numeric.boolean.expression_semantics"></a></span><a class="link" href="boolean.html#spirit.qi.reference.numeric.boolean.expression_semantics">Expression
204            Semantics</a>
205          </h6>
206<p>
207            Semantics of an expression is defined only where it differs from, or
208            is not defined in <a class="link" href="../parser_concepts/primitiveparser.html" title="PrimitiveParser"><code class="computeroutput"><span class="identifier">PrimitiveParser</span></code></a>.
209          </p>
210<div class="informaltable"><table class="table">
211<colgroup>
212<col>
213<col>
214</colgroup>
215<thead><tr>
216<th>
217                    <p>
218                      Expression
219                    </p>
220                  </th>
221<th>
222                    <p>
223                      Semantics
224                    </p>
225                  </th>
226</tr></thead>
227<tbody>
228<tr>
229<td>
230                    <p>
231</p>
232<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">bool_</span>
233</pre>
234<p>
235                    </p>
236                  </td>
237<td>
238                    <p>
239                      Parse a boolean using the default policies (<code class="computeroutput"><span class="identifier">bool_policies</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>).
240                    </p>
241                  </td>
242</tr>
243<tr>
244<td>
245                    <p>
246</p>
247<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">lit</span><span class="special">(</span><span class="identifier">boolean</span><span class="special">)</span>
248<span class="identifier">bool_</span><span class="special">(</span><span class="identifier">boolean</span><span class="special">)</span>
249</pre>
250<p>
251                    </p>
252                  </td>
253<td>
254                    <p>
255                      Match the literal <code class="computeroutput"><span class="identifier">boolean</span></code>
256                      using the default policies (<code class="computeroutput"><span class="identifier">bool_policies</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>). The parser will fail
257                      if the parsed value is not equal to the specified value.
258                    </p>
259                  </td>
260</tr>
261<tr>
262<td>
263                    <p>
264</p>
265<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">true_</span>
266<span class="identifier">false_</span>
267</pre>
268<p>
269                    </p>
270                  </td>
271<td>
272                    <p>
273                      Match <code class="computeroutput"><span class="string">"true"</span></code>
274                      and <code class="computeroutput"><span class="string">"false"</span></code>,
275                      respectively.
276                    </p>
277                  </td>
278</tr>
279<tr>
280<td>
281                    <p>
282</p>
283<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">bool_parser</span><span class="special">&lt;</span>
284    <span class="identifier">T</span><span class="special">,</span> <span class="identifier">BoolPolicies</span>
285<span class="special">&gt;()</span>
286</pre>
287<p>
288                    </p>
289                  </td>
290<td>
291                    <p>
292                      Parse a real of type <code class="computeroutput"><span class="identifier">T</span></code>
293                      using <code class="computeroutput"><span class="identifier">BoolPolicies</span></code>.
294                    </p>
295                  </td>
296</tr>
297<tr>
298<td>
299                    <p>
300</p>
301<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">bool_parser</span><span class="special">&lt;</span>
302    <span class="identifier">T</span><span class="special">,</span> <span class="identifier">BoolPolicies</span>
303<span class="special">&gt;()(</span><span class="identifier">boolean</span><span class="special">)</span>
304</pre>
305<p>
306                    </p>
307                  </td>
308<td>
309                    <p>
310                      Match the literal <code class="computeroutput"><span class="identifier">boolean</span></code>
311                      of type <code class="computeroutput"><span class="identifier">T</span></code> using
312                      <code class="computeroutput"><span class="identifier">BoolPolicies</span></code>.
313                      The parser will fail if the parsed value is not equal to the
314                      specified value.
315                    </p>
316                  </td>
317</tr>
318</tbody>
319</table></div>
320<div class="note"><table border="0" summary="Note">
321<tr>
322<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
323<th align="left">Note</th>
324</tr>
325<tr><td align="left" valign="top"><p>
326              All boolean parsers properly respect the <a class="link" href="../directive/no_case.html" title="Parser Directive Inhibiting Case Sensitivity (no_case[])"><code class="computeroutput"><span class="identifier">no_case</span></code></a><code class="computeroutput"><span class="special">[]</span></code>
327              directive.
328            </p></td></tr>
329</table></div>
330<h6>
331<a name="spirit.qi.reference.numeric.boolean.h7"></a>
332            <span class="phrase"><a name="spirit.qi.reference.numeric.boolean.attributes"></a></span><a class="link" href="boolean.html#spirit.qi.reference.numeric.boolean.attributes">Attributes</a>
333          </h6>
334<div class="informaltable"><table class="table">
335<colgroup>
336<col>
337<col>
338</colgroup>
339<thead><tr>
340<th>
341                    <p>
342                      Expression
343                    </p>
344                  </th>
345<th>
346                    <p>
347                      Attribute
348                    </p>
349                  </th>
350</tr></thead>
351<tbody>
352<tr>
353<td>
354                    <p>
355</p>
356<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">lit</span><span class="special">(</span><span class="identifier">boolean</span><span class="special">)</span>
357</pre>
358<p>
359                    </p>
360                  </td>
361<td>
362                    <p>
363                      <code class="computeroutput"><span class="identifier">unused</span></code>
364                    </p>
365                  </td>
366</tr>
367<tr>
368<td>
369                    <p>
370</p>
371<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">true_</span>
372<span class="identifier">false_</span>
373<span class="identifier">bool_</span>
374<span class="identifier">bool_</span><span class="special">(</span><span class="identifier">boolean</span><span class="special">)</span>
375</pre>
376<p>
377                    </p>
378                  </td>
379<td>
380                    <p>
381                      <code class="computeroutput"><span class="keyword">bool</span></code>
382                    </p>
383                  </td>
384</tr>
385<tr>
386<td>
387                    <p>
388</p>
389<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">bool_parser</span><span class="special">&lt;</span>
390    <span class="identifier">T</span><span class="special">,</span> <span class="identifier">BoolPolicies</span>
391<span class="special">&gt;()</span>
392<span class="identifier">bool_parser</span><span class="special">&lt;</span>
393    <span class="identifier">T</span><span class="special">,</span> <span class="identifier">BoolPolicies</span>
394<span class="special">&gt;()(</span><span class="identifier">num</span><span class="special">)</span>
395</pre>
396<p>
397                    </p>
398                  </td>
399<td>
400                    <p>
401                      <code class="computeroutput"><span class="identifier">T</span></code>
402                    </p>
403                  </td>
404</tr>
405</tbody>
406</table></div>
407<h6>
408<a name="spirit.qi.reference.numeric.boolean.h8"></a>
409            <span class="phrase"><a name="spirit.qi.reference.numeric.boolean.complexity"></a></span><a class="link" href="boolean.html#spirit.qi.reference.numeric.boolean.complexity">Complexity</a>
410          </h6>
411<div class="blockquote"><blockquote class="blockquote"><p>
412              O(N), where N is the number of characters being parsed.
413            </p></blockquote></div>
414<h6>
415<a name="spirit.qi.reference.numeric.boolean.h9"></a>
416            <span class="phrase"><a name="spirit.qi.reference.numeric.boolean.minimum_expression_requirements_for__code__phrase_role__identifier__b__phrase___code_"></a></span><a class="link" href="boolean.html#spirit.qi.reference.numeric.boolean.minimum_expression_requirements_for__code__phrase_role__identifier__b__phrase___code_">Minimum
417            Expression Requirements for <code class="computeroutput"><span class="identifier">B</span></code></a>
418          </h6>
419<p>
420            The boolean type, <code class="computeroutput"><span class="identifier">B</span></code>,
421            the minimum expression requirements listed below must be valid. Take
422            note that additional requirements may be imposed by custom policies.
423          </p>
424<div class="informaltable"><table class="table">
425<colgroup>
426<col>
427<col>
428</colgroup>
429<thead><tr>
430<th>
431                    <p>
432                      Expression
433                    </p>
434                  </th>
435<th>
436                    <p>
437                      Semantics
438                    </p>
439                  </th>
440</tr></thead>
441<tbody><tr>
442<td>
443                    <p>
444                      <code class="computeroutput"><span class="identifier">B</span><span class="special">(</span><span class="keyword">bool</span><span class="special">)</span></code>
445                    </p>
446                  </td>
447<td>
448                    <p>
449                      Constructible from a <code class="computeroutput"><span class="keyword">bool</span></code>.
450                    </p>
451                  </td>
452</tr></tbody>
453</table></div>
454<h6>
455<a name="spirit.qi.reference.numeric.boolean.h10"></a>
456            <span class="phrase"><a name="spirit.qi.reference.numeric.boolean.boolean__code__phrase_role__identifier__policies__phrase___code_"></a></span><a class="link" href="boolean.html#spirit.qi.reference.numeric.boolean.boolean__code__phrase_role__identifier__policies__phrase___code_">Boolean
457            <code class="computeroutput"><span class="identifier">Policies</span></code></a>
458          </h6>
459<p>
460            The boolean <code class="computeroutput"><span class="identifier">Policies</span></code>
461            template parameter is a class that groups all the policies that control
462            the parser's behavior. Policies control the boolean parsers' behavior.
463          </p>
464<p>
465            The default is <code class="computeroutput"><span class="identifier">bool_policies</span><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">&gt;</span></code>. The default is provided to take
466            care of the most common case (there are many ways to represent, and hence
467            parse, boolean numbers). In most cases, the default policies are sufficient
468            and can be used straight out of the box. They are designed to parse boolean
469            value of the form <code class="computeroutput"><span class="string">"true"</span></code>
470            and <code class="computeroutput"><span class="string">"false"</span></code>.
471          </p>
472<h6>
473<a name="spirit.qi.reference.numeric.boolean.h11"></a>
474            <span class="phrase"><a name="spirit.qi.reference.numeric.boolean.boolean__code__phrase_role__identifier__policies__phrase___code__expression_requirements"></a></span><a class="link" href="boolean.html#spirit.qi.reference.numeric.boolean.boolean__code__phrase_role__identifier__policies__phrase___code__expression_requirements">Boolean
475            <code class="computeroutput"><span class="identifier">Policies</span></code> Expression Requirements</a>
476          </h6>
477<p>
478            For models of boolean <code class="computeroutput"><span class="identifier">Policies</span></code>
479            the following expressions must be valid:
480          </p>
481<div class="informaltable"><table class="table">
482<colgroup>
483<col>
484<col>
485</colgroup>
486<thead><tr>
487<th>
488                    <p>
489                      Expression
490                    </p>
491                  </th>
492<th>
493                    <p>
494                      Semantics
495                    </p>
496                  </th>
497</tr></thead>
498<tbody>
499<tr>
500<td>
501                    <p>
502                      <code class="computeroutput"><span class="identifier">BP</span><span class="special">::</span><span class="identifier">parse_true</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span>
503                      <span class="identifier">l</span><span class="special">,</span>
504                      <span class="identifier">attr</span><span class="special">)</span></code>
505                    </p>
506                  </td>
507<td>
508                    <p>
509                      Parse a <code class="computeroutput"><span class="keyword">true</span></code> value.
510                    </p>
511                  </td>
512</tr>
513<tr>
514<td>
515                    <p>
516                      <code class="computeroutput"><span class="identifier">BP</span><span class="special">::</span><span class="identifier">parse_false</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span>
517                      <span class="identifier">l</span><span class="special">,</span>
518                      <span class="identifier">attr</span><span class="special">)</span></code>
519                    </p>
520                  </td>
521<td>
522                    <p>
523                      Parse a <code class="computeroutput"><span class="keyword">false</span></code>
524                      value.
525                    </p>
526                  </td>
527</tr>
528</tbody>
529</table></div>
530<p>
531            The functions should return true if the required representations of
532            <code class="computeroutput"><span class="keyword">true</span></code> or <code class="computeroutput"><span class="keyword">false</span></code>
533            have been found. In this case the attribute <code class="computeroutput"><span class="identifier">n</span></code>
534            should be set to the matched value (<code class="computeroutput"><span class="keyword">true</span></code>
535            or <code class="computeroutput"><span class="keyword">false</span></code>).
536          </p>
537<h6>
538<a name="spirit.qi.reference.numeric.boolean.h12"></a>
539            <span class="phrase"><a name="spirit.qi.reference.numeric.boolean.boolean__code__phrase_role__identifier__policies__phrase___code__specializations"></a></span><a class="link" href="boolean.html#spirit.qi.reference.numeric.boolean.boolean__code__phrase_role__identifier__policies__phrase___code__specializations">Boolean
540            <code class="computeroutput"><span class="identifier">Policies</span></code> Specializations</a>
541          </h6>
542<p>
543            The easiest way to implement a proper boolean parsing policy is to derive
544            a new type from the type <code class="computeroutput"><span class="identifier">bool_policies</span></code>
545            while overriding the aspects of the parsing which need to be changed.
546            For example, here's the implementation of a boolean parsing policy interpreting
547            the string <code class="computeroutput"><span class="string">"eurt"</span></code>
548            (i.e. "true" spelled backwards) as <code class="computeroutput"><span class="keyword">false</span></code>:
549          </p>
550<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">backwards_bool_policies</span> <span class="special">:</span> <span class="identifier">qi</span><span class="special">::</span><span class="identifier">bool_policies</span><span class="special">&lt;&gt;</span>
551<span class="special">{</span>
552    <span class="comment">// we want to interpret a 'true' spelled backwards as 'false'</span>
553    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attribute</span><span class="special">&gt;</span>
554    <span class="keyword">static</span> <span class="keyword">bool</span>
555    <span class="identifier">parse_false</span><span class="special">(</span><span class="identifier">Iterator</span><span class="special">&amp;</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">Iterator</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">Attribute</span><span class="special">&amp;</span> <span class="identifier">attr</span><span class="special">)</span>
556    <span class="special">{</span>
557        <span class="keyword">namespace</span> <span class="identifier">qi</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">;</span>
558        <span class="keyword">if</span> <span class="special">(</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">string_parse</span><span class="special">(</span><span class="string">"eurt"</span><span class="special">,</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">qi</span><span class="special">::</span><span class="identifier">unused</span><span class="special">))</span>
559        <span class="special">{</span>
560            <span class="identifier">spirit</span><span class="special">::</span><span class="identifier">traits</span><span class="special">::</span><span class="identifier">assign_to</span><span class="special">(</span><span class="keyword">false</span><span class="special">,</span> <span class="identifier">attr</span><span class="special">);</span>    <span class="comment">// result is false</span>
561            <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
562        <span class="special">}</span>
563        <span class="keyword">return</span> <span class="keyword">false</span><span class="special">;</span>
564    <span class="special">}</span>
565<span class="special">};</span>
566</pre>
567<h6>
568<a name="spirit.qi.reference.numeric.boolean.h13"></a>
569            <span class="phrase"><a name="spirit.qi.reference.numeric.boolean.example"></a></span><a class="link" href="boolean.html#spirit.qi.reference.numeric.boolean.example">Example</a>
570          </h6>
571<div class="note"><table border="0" summary="Note">
572<tr>
573<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
574<th align="left">Note</th>
575</tr>
576<tr><td align="left" valign="top"><p>
577              The test harness for the example(s) below is presented in the <a class="link" href="../basics.html#spirit.qi.reference.basics.examples">Basics Examples</a>
578              section.
579            </p></td></tr>
580</table></div>
581<p>
582            Some using declarations:
583          </p>
584<p>
585</p>
586<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">val</span><span class="special">;</span>
587<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">qi</span><span class="special">::</span><span class="identifier">bool_</span><span class="special">;</span>
588<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">qi</span><span class="special">::</span><span class="identifier">bool_parser</span><span class="special">;</span>
589<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">qi</span><span class="special">::</span><span class="identifier">lit</span><span class="special">;</span>
590</pre>
591<p>
592          </p>
593<p>
594            Basic real number parsing:
595          </p>
596<p>
597</p>
598<pre class="programlisting"><span class="comment">// bool</span>
599<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"true"</span><span class="special">,</span> <span class="identifier">bool_</span><span class="special">);</span>
600<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"false"</span><span class="special">,</span> <span class="identifier">bool_</span><span class="special">);</span>
601<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"true"</span><span class="special">,</span> <span class="identifier">bool_</span><span class="special">(</span><span class="keyword">true</span><span class="special">));</span>
602<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"false"</span><span class="special">,</span> <span class="identifier">bool_</span><span class="special">(</span><span class="keyword">false</span><span class="special">));</span>
603<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"true"</span><span class="special">,</span> <span class="identifier">bool_</span><span class="special">(</span><span class="identifier">val</span><span class="special">(</span><span class="keyword">true</span><span class="special">)));</span>
604<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"false"</span><span class="special">,</span> <span class="identifier">bool_</span><span class="special">(</span><span class="identifier">val</span><span class="special">(</span><span class="keyword">false</span><span class="special">)));</span>
605
606<span class="comment">// literals</span>
607<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"true"</span><span class="special">,</span> <span class="identifier">lit</span><span class="special">(</span><span class="keyword">true</span><span class="special">));</span>
608<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"false"</span><span class="special">,</span> <span class="identifier">lit</span><span class="special">(</span><span class="keyword">false</span><span class="special">));</span>
609<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"true"</span><span class="special">,</span> <span class="identifier">lit</span><span class="special">(</span><span class="identifier">val</span><span class="special">(</span><span class="keyword">true</span><span class="special">)));</span>
610<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"false"</span><span class="special">,</span> <span class="identifier">lit</span><span class="special">(</span><span class="identifier">val</span><span class="special">(</span><span class="keyword">false</span><span class="special">)));</span>
611</pre>
612<p>
613          </p>
614<p>
615            A custom real number policy:
616          </p>
617<p>
618</p>
619<pre class="programlisting"><span class="comment">///////////////////////////////////////////////////////////////////////////////</span>
620<span class="comment">//  These policies can be used to parse "eurt" (i.e. "true" spelled backwards)</span>
621<span class="comment">//  as `false`</span>
622<span class="comment">///////////////////////////////////////////////////////////////////////////////</span>
623<span class="keyword">struct</span> <span class="identifier">backwards_bool_policies</span> <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">bool_policies</span><span class="special">&lt;&gt;</span>
624<span class="special">{</span>
625    <span class="comment">// we want to interpret a 'true' spelled backwards as 'false'</span>
626    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attribute</span><span class="special">&gt;</span>
627    <span class="keyword">static</span> <span class="keyword">bool</span>
628    <span class="identifier">parse_false</span><span class="special">(</span><span class="identifier">Iterator</span><span class="special">&amp;</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">Iterator</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">Attribute</span><span class="special">&amp;</span> <span class="identifier">attr</span><span class="special">)</span>
629    <span class="special">{</span>
630        <span class="keyword">namespace</span> <span class="identifier">qi</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">;</span>
631        <span class="keyword">if</span> <span class="special">(</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">string_parse</span><span class="special">(</span><span class="string">"eurt"</span><span class="special">,</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">qi</span><span class="special">::</span><span class="identifier">unused</span><span class="special">))</span>
632        <span class="special">{</span>
633            <span class="keyword">namespace</span> <span class="identifier">traits</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">traits</span><span class="special">;</span>
634            <span class="identifier">traits</span><span class="special">::</span><span class="identifier">assign_to</span><span class="special">(</span><span class="keyword">false</span><span class="special">,</span> <span class="identifier">attr</span><span class="special">);</span>    <span class="comment">// result is false</span>
635            <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
636        <span class="special">}</span>
637        <span class="keyword">return</span> <span class="keyword">false</span><span class="special">;</span>
638    <span class="special">}</span>
639<span class="special">};</span>
640</pre>
641<p>
642          </p>
643<p>
644            And its use:
645          </p>
646<p>
647</p>
648<pre class="programlisting"><span class="identifier">bool_parser</span><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">,</span> <span class="identifier">backwards_bool_policies</span><span class="special">&gt;</span> <span class="identifier">backwards_bool</span><span class="special">;</span>
649<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"true"</span><span class="special">,</span> <span class="identifier">backwards_bool</span><span class="special">);</span>
650<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"eurt"</span><span class="special">,</span> <span class="identifier">backwards_bool</span><span class="special">);</span>
651<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"true"</span><span class="special">,</span> <span class="identifier">backwards_bool</span><span class="special">(</span><span class="keyword">true</span><span class="special">));</span>
652<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"eurt"</span><span class="special">,</span> <span class="identifier">backwards_bool</span><span class="special">(</span><span class="keyword">false</span><span class="special">));</span>
653</pre>
654<p>
655          </p>
656</div>
657<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
658<td align="left"></td>
659<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
660        Distributed under the Boost Software License, Version 1.0. (See accompanying
661        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>)
662      </p>
663</div></td>
664</tr></table>
665<hr>
666<div class="spirit-nav">
667<a accesskey="p" href="real.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="../operator.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
668</div>
669</body>
670</html>
671