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