1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Auto Generator</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="../reference.html" title="Reference"> 9<link rel="prev" href="action.html" title="Semantic Actions with Generators"> 10<link rel="next" href="auxiliary.html" title="Auxiliary Generators"> 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="action.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.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="auxiliary.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h4 class="title"> 27<a name="spirit.karma.reference.auto"></a><a class="link" href="auto.html" title="Auto Generator">Auto Generator</a> 28</h4></div></div></div> 29<h6> 30<a name="spirit.karma.reference.auto.h0"></a> 31 <span class="phrase"><a name="spirit.karma.reference.auto.description"></a></span><a class="link" href="auto.html#spirit.karma.reference.auto.description">Description</a> 32 </h6> 33<p> 34 This module includes the description of the <code class="computeroutput"><span class="identifier">auto_</span></code> 35 generator. This generator can be used to automatically create a generator 36 based on the supplied attribute type. 37 </p> 38<h6> 39<a name="spirit.karma.reference.auto.h1"></a> 40 <span class="phrase"><a name="spirit.karma.reference.auto.header"></a></span><a class="link" href="auto.html#spirit.karma.reference.auto.header">Header</a> 41 </h6> 42<pre class="programlisting"><span class="comment">// forwards to <boost/spirit/home/karma/auto.hpp></span> 43<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_auto</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 44</pre> 45<p> 46 Also, see <a class="link" href="../../structure/include.html" title="Include">Include Structure</a>. 47 </p> 48<h6> 49<a name="spirit.karma.reference.auto.h2"></a> 50 <span class="phrase"><a name="spirit.karma.reference.auto.namespace"></a></span><a class="link" href="auto.html#spirit.karma.reference.auto.namespace">Namespace</a> 51 </h6> 52<div class="informaltable"><table class="table"> 53<colgroup><col></colgroup> 54<thead><tr><th> 55 <p> 56 Name 57 </p> 58 </th></tr></thead> 59<tbody><tr><td> 60 <p> 61 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">auto_</span> <span class="comment">// alias: 62 boost::spirit::karma::auto_</span></code> 63 </p> 64 </td></tr></tbody> 65</table></div> 66<h6> 67<a name="spirit.karma.reference.auto.h3"></a> 68 <span class="phrase"><a name="spirit.karma.reference.auto.model_of"></a></span><a class="link" href="auto.html#spirit.karma.reference.auto.model_of">Model 69 of</a> 70 </h6> 71<div class="blockquote"><blockquote class="blockquote"><p> 72 <a class="link" href="generator_concepts/primitivegenerator.html" title="PrimitiveGenerator"><code class="computeroutput"><span class="identifier">PrimitiveGenerator</span></code></a> 73 </p></blockquote></div> 74<div class="variablelist"> 75<p class="title"><b>Notation</b></p> 76<dl class="variablelist"> 77<dt><span class="term"><code class="computeroutput"><span class="identifier">s</span></code></span></dt> 78<dd><p> 79 A variable instance of any type for which a mapping to a generator 80 type is defined (the meta function <code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">create_generator_exists</span></code> 81 returns <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">true_</span></code>) or a <a class="link" href="basics.html#spirit.karma.reference.basics.lazy_argument">Lazy 82 Argument</a> that evaluates to any type for which a mapping to 83 a generator type is defined (the meta function <code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">create_generator_exists</span></code> 84 returns <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">true_</span></code>). 85 </p></dd> 86</dl> 87</div> 88<h6> 89<a name="spirit.karma.reference.auto.h4"></a> 90 <span class="phrase"><a name="spirit.karma.reference.auto.expression_semantics"></a></span><a class="link" href="auto.html#spirit.karma.reference.auto.expression_semantics">Expression 91 Semantics</a> 92 </h6> 93<p> 94 Semantics of an expression is defined only where it differs from, or is 95 not defined in <a class="link" href="generator_concepts/primitivegenerator.html" title="PrimitiveGenerator"><code class="computeroutput"><span class="identifier">PrimitiveGenerator</span></code></a>. 96 </p> 97<div class="informaltable"><table class="table"> 98<colgroup> 99<col> 100<col> 101</colgroup> 102<thead><tr> 103<th> 104 <p> 105 Expression 106 </p> 107 </th> 108<th> 109 <p> 110 Description 111 </p> 112 </th> 113</tr></thead> 114<tbody> 115<tr> 116<td> 117 <p> 118 <code class="computeroutput"><span class="identifier">auto_</span></code> 119 </p> 120 </td> 121<td> 122 <p> 123 Create a generator instance compatible with the supplied attribute 124 type and use it for output generation. This generator never fails 125 (unless the underlying output stream reports an error). 126 </p> 127 </td> 128</tr> 129<tr> 130<td> 131 <p> 132 <code class="computeroutput"><span class="identifier">auto_</span><span class="special">(</span><span class="identifier">s</span><span class="special">)</span></code> 133 </p> 134 </td> 135<td> 136 <p> 137 Create a generator instance compatible with the supplied literal 138 value. This generator never fails (unless the underlying output 139 stream reports an error). 140 </p> 141 </td> 142</tr> 143</tbody> 144</table></div> 145<h6> 146<a name="spirit.karma.reference.auto.h5"></a> 147 <span class="phrase"><a name="spirit.karma.reference.auto.additional_requirements"></a></span><a class="link" href="auto.html#spirit.karma.reference.auto.additional_requirements">Additional 148 Requirements</a> 149 </h6> 150<p> 151 The <code class="computeroutput"><span class="identifier">auto_</span></code> generators can 152 be used to emit output for any data type for which a mapping to a generator 153 type is defined (the meta function <code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">create_generator_exists</span></code> 154 returns <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">true_</span></code>). The following table outlines 155 the predefined mapping rules from the attribute type to the generator type. 156 These rules are applied recursively to create the generator type which 157 can be used to generate output from the given attribute type. 158 </p> 159<div class="informaltable"><table class="table"> 160<colgroup> 161<col> 162<col> 163</colgroup> 164<thead><tr> 165<th> 166 <p> 167 Attribute type 168 </p> 169 </th> 170<th> 171 <p> 172 Generator type 173 </p> 174 </th> 175</tr></thead> 176<tbody> 177<tr> 178<td> 179 <p> 180 <code class="computeroutput"><span class="keyword">char</span></code>, <code class="computeroutput"><span class="keyword">wchar_t</span></code> 181 </p> 182 </td> 183<td> 184 <p> 185 <code class="computeroutput"><span class="identifier">standard</span><span class="special">::</span><span class="identifier">char_</span></code>, <code class="computeroutput"><span class="identifier">standard_wide</span><span class="special">::</span><span class="identifier">char_</span></code> 186 </p> 187 </td> 188</tr> 189<tr> 190<td> 191 <p> 192 <code class="computeroutput"><span class="keyword">short</span></code>, <code class="computeroutput"><span class="keyword">int</span></code>, <code class="computeroutput"><span class="keyword">long</span></code> 193 </p> 194 </td> 195<td> 196 <p> 197 <code class="computeroutput"><span class="identifier">short_</span></code>, <code class="computeroutput"><span class="identifier">int_</span></code>, <code class="computeroutput"><span class="identifier">long_</span></code> 198 </p> 199 </td> 200</tr> 201<tr> 202<td> 203 <p> 204 <code class="computeroutput"><span class="keyword">unsigned</span> <span class="keyword">short</span></code>, 205 <code class="computeroutput"><span class="keyword">unsigned</span> <span class="keyword">int</span></code>, 206 <code class="computeroutput"><span class="keyword">unsigned</span> <span class="keyword">long</span></code> 207 </p> 208 </td> 209<td> 210 <p> 211 <code class="computeroutput"><span class="identifier">ushort_</span></code>, <code class="computeroutput"><span class="identifier">uint_</span></code>, <code class="computeroutput"><span class="identifier">ulong_</span></code> 212 </p> 213 </td> 214</tr> 215<tr> 216<td> 217 <p> 218 <code class="computeroutput"><span class="keyword">float</span></code>, <code class="computeroutput"><span class="keyword">double</span></code>, <code class="computeroutput"><span class="keyword">long</span> 219 <span class="keyword">double</span></code> 220 </p> 221 </td> 222<td> 223 <p> 224 <code class="computeroutput"><span class="identifier">float_</span></code>, <code class="computeroutput"><span class="identifier">double_</span></code>, <code class="computeroutput"><span class="identifier">long_double</span></code> 225 </p> 226 </td> 227</tr> 228<tr> 229<td> 230 <p> 231 <code class="computeroutput"><span class="keyword">short</span></code>, <code class="computeroutput"><span class="keyword">int</span></code>, <code class="computeroutput"><span class="keyword">long</span></code> 232 </p> 233 </td> 234<td> 235 <p> 236 <code class="computeroutput"><span class="identifier">short_</span></code>, <code class="computeroutput"><span class="identifier">int_</span></code>, <code class="computeroutput"><span class="identifier">long_</span></code> 237 </p> 238 </td> 239</tr> 240<tr> 241<td> 242 <p> 243 <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">long</span></code>, 244 <code class="computeroutput"><span class="keyword">unsigned</span> <span class="keyword">long</span> 245 <span class="keyword">long</span></code> 246 </p> 247 </td> 248<td> 249 <p> 250 <code class="computeroutput"><span class="identifier">long_long</span></code>, <code class="computeroutput"><span class="identifier">ulong_long</span></code> 251 </p> 252 </td> 253</tr> 254<tr> 255<td> 256 <p> 257 <code class="computeroutput"><span class="keyword">bool</span></code> 258 </p> 259 </td> 260<td> 261 <p> 262 <code class="computeroutput"><span class="identifier">bool_</span></code> 263 </p> 264 </td> 265</tr> 266<tr> 267<td> 268 <p> 269 Any string (<code class="computeroutput"><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span></code>, 270 <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span></code>, etc.) 271 </p> 272 </td> 273<td> 274 <p> 275 <code class="computeroutput"><span class="identifier">string</span></code> 276 </p> 277 </td> 278</tr> 279<tr> 280<td> 281 <p> 282 Any (STL) container 283 </p> 284 </td> 285<td> 286 <p> 287 Kleene Star (unary <code class="computeroutput"><span class="char">'*'</span></code>) 288 </p> 289 </td> 290</tr> 291<tr> 292<td> 293 <p> 294 Any Fusion sequence 295 </p> 296 </td> 297<td> 298 <p> 299 Sequence operator (<code class="computeroutput"><span class="char">'<<'</span></code>) 300 </p> 301 </td> 302</tr> 303<tr> 304<td> 305 <p> 306 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special"><></span></code> 307 </p> 308 </td> 309<td> 310 <p> 311 Optional operator (unary <code class="computeroutput"><span class="char">'-'</span></code>) 312 </p> 313 </td> 314</tr> 315<tr> 316<td> 317 <p> 318 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">variant</span><span class="special"><></span></code> 319 </p> 320 </td> 321<td> 322 <p> 323 Alternative operator (<code class="computeroutput"><span class="char">'|'</span></code>) 324 </p> 325 </td> 326</tr> 327</tbody> 328</table></div> 329<p> 330 It is possible to add support for any custom data type by implementing 331 a specialization of the customization point <a class="link" href="../../advanced/customize/auto/create_generator.html" title="Define a Custom Attribute Mapping for a Generator"><code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">create_generator</span></code></a>. This customization 332 can be used also to redefined any of the predefined mappings. 333 </p> 334<h6> 335<a name="spirit.karma.reference.auto.h6"></a> 336 <span class="phrase"><a name="spirit.karma.reference.auto.attributes"></a></span><a class="link" href="auto.html#spirit.karma.reference.auto.attributes">Attributes</a> 337 </h6> 338<div class="informaltable"><table class="table"> 339<colgroup> 340<col> 341<col> 342</colgroup> 343<thead><tr> 344<th> 345 <p> 346 Expression 347 </p> 348 </th> 349<th> 350 <p> 351 Attribute 352 </p> 353 </th> 354</tr></thead> 355<tbody> 356<tr> 357<td> 358 <p> 359 <code class="computeroutput"><span class="identifier">auto_</span></code> 360 </p> 361 </td> 362<td> 363 <p> 364 <code class="computeroutput"><span class="identifier">hold_any</span></code>, attribute 365 is mandatory (otherwise compilation will fail) 366 </p> 367 </td> 368</tr> 369<tr> 370<td> 371 <p> 372 <code class="computeroutput"><span class="identifier">auto_</span><span class="special">(</span><span class="identifier">s</span><span class="special">)</span></code> 373 </p> 374 </td> 375<td> 376 <p> 377 <code class="computeroutput"><span class="identifier">unused</span></code> 378 </p> 379 </td> 380</tr> 381</tbody> 382</table></div> 383<div class="important"><table border="0" summary="Important"> 384<tr> 385<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../images/important.png"></td> 386<th align="left">Important</th> 387</tr> 388<tr><td align="left" valign="top"><p> 389 The attribute type <code class="computeroutput"><span class="identifier">hold_any</span></code> 390 exposed by some of the <code class="computeroutput"><span class="identifier">auto_</span></code> 391 generators is semantically and syntactically equivalent to the type implemented 392 by <a href="../../../../../../../libs/any/index.html" target="_top">Boost.Any</a>. It has 393 been added to <span class="emphasis"><em>Spirit</em></span> as it has better a performance 394 and a smaller footprint if compared to <a href="../../../../../../../libs/any/index.html" target="_top">Boost.Any</a>. 395 </p></td></tr> 396</table></div> 397<div class="note"><table border="0" summary="Note"> 398<tr> 399<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../images/note.png"></td> 400<th align="left">Note</th> 401</tr> 402<tr><td align="left" valign="top"><p> 403 In addition to their usual attribute of type <code class="computeroutput"><span class="identifier">Attrib</span></code> 404 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">Attrib</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) 405 the generators behave as if their attribute was an instance of <code class="computeroutput"><span class="identifier">Attrib</span></code> and emit the value stored in 406 the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special"><></span></code>. 407 Otherwise the generators will fail. 408 </p></td></tr> 409</table></div> 410<h6> 411<a name="spirit.karma.reference.auto.h7"></a> 412 <span class="phrase"><a name="spirit.karma.reference.auto.complexity"></a></span><a class="link" href="auto.html#spirit.karma.reference.auto.complexity">Complexity</a> 413 </h6> 414<div class="blockquote"><blockquote class="blockquote"><p> 415 The complexity of the <code class="computeroutput"><span class="identifier">auto_</span></code> 416 generator depends on the attribute type. Each attribute type results 417 in a different generator type to be instantiated which defines the overall 418 complexity. 419 </p></blockquote></div> 420<h6> 421<a name="spirit.karma.reference.auto.h8"></a> 422 <span class="phrase"><a name="spirit.karma.reference.auto.example"></a></span><a class="link" href="auto.html#spirit.karma.reference.auto.example">Example</a> 423 </h6> 424<div class="note"><table border="0" summary="Note"> 425<tr> 426<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../images/note.png"></td> 427<th align="left">Note</th> 428</tr> 429<tr><td align="left" valign="top"><p> 430 The test harness for the example(s) below is presented in the <a class="link" href="basics.html#spirit.karma.reference.basics.examples">Basics 431 Examples</a> section. 432 </p></td></tr> 433</table></div> 434<p> 435 Some includes: 436 </p> 437<p> 438</p> 439<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> 440<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> 441<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> 442<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> 443<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> 444<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 445<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">string</span><span class="special">></span> 446</pre> 447<p> 448 </p> 449<p> 450 Some using declarations: 451 </p> 452<p> 453</p> 454<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">auto_</span><span class="special">;</span> 455</pre> 456<p> 457 </p> 458<p> 459 And a class definition used in the examples: 460 </p> 461<p> 462</p> 463<pre class="programlisting"><span class="comment">// a simple complex number representation z = a + bi</span> 464<span class="keyword">struct</span> <span class="identifier">complex</span> 465<span class="special">{</span> 466 <span class="identifier">complex</span> <span class="special">(</span><span class="keyword">double</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">b</span><span class="special">)</span> 467 <span class="special">:</span> <span class="identifier">a</span><span class="special">(</span><span class="identifier">a</span><span class="special">),</span> <span class="identifier">b</span><span class="special">(</span><span class="identifier">b</span><span class="special">)</span> 468 <span class="special">{}</span> 469 470 <span class="keyword">double</span> <span class="identifier">a</span><span class="special">;</span> 471 <span class="keyword">double</span> <span class="identifier">b</span><span class="special">;</span> 472<span class="special">};</span> 473</pre> 474<p> 475 </p> 476<p> 477 The following construct is required to allow the <code class="computeroutput"><span class="identifier">complex</span></code> 478 data structure to be utilized as a <a href="../../../../../../../libs/fusion/doc/html/index.html" target="_top">Boost.Fusion</a> 479 sequence. This is required as we will emit output for this data structure 480 with a <span class="emphasis"><em>Spirit.Karma</em></span> sequence: <code class="computeroutput"><span class="char">'{'</span> 481 <span class="special"><<</span> <span class="identifier">karma</span><span class="special">::</span><span class="identifier">double_</span> <span class="special"><<</span> <span class="char">','</span> <span class="special"><<</span> <span class="identifier">karma</span><span class="special">::</span><span class="identifier">double_</span> <span class="special"><<</span> <span class="char">'}'</span></code>. 482 </p> 483<p> 484</p> 485<pre class="programlisting"><span class="identifier">BOOST_FUSION_ADAPT_STRUCT</span><span class="special">(</span> 486 <span class="identifier">complex</span><span class="special">,</span> 487 <span class="special">(</span><span class="keyword">double</span><span class="special">,</span> <span class="identifier">a</span><span class="special">)</span> 488 <span class="special">(</span><span class="keyword">double</span><span class="special">,</span> <span class="identifier">b</span><span class="special">)</span> 489<span class="special">)</span> 490</pre> 491<p> 492 </p> 493<p> 494 We add a specialization for the create_generator customization point defining 495 a custom output format for the complex type. Generally, any specialization 496 for create_generator is expected to return the proto expression to be used 497 to generate output for the type the customization point has been specialized 498 for. 499 </p> 500<p> 501 We need to utilize <code class="computeroutput"><span class="identifier">proto</span><span class="special">::</span><span class="identifier">deep_copy</span></code> 502 as the expression contains literals (the <code class="computeroutput"><span class="char">'{'</span></code>, 503 <code class="computeroutput"><span class="char">','</span></code>, and <code class="computeroutput"><span class="char">'}'</span></code>) 504 which normally get embedded in the proto expression by reference only. 505 The deep copy converts the proto tree to hold this by value. The deep copy 506 operation can be left out for simpler proto expressions (not containing 507 references to temporaries). Alternatively you could use the <code class="computeroutput"><span class="identifier">proto</span><span class="special">::</span><span class="identifier">make_expr</span></code> facility to build the required 508 proto expression. 509 </p> 510<p> 511</p> 512<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">spirit</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">traits</span> 513<span class="special">{</span> 514 <span class="keyword">template</span> <span class="special"><></span> 515 <span class="keyword">struct</span> <span class="identifier">create_generator</span><span class="special"><</span><span class="identifier">complex</span><span class="special">></span> 516 <span class="special">{</span> 517 <span class="keyword">typedef</span> <span class="identifier">proto</span><span class="special">::</span><span class="identifier">result_of</span><span class="special">::</span><span class="identifier">deep_copy</span><span class="special"><</span> 518 <span class="identifier">BOOST_TYPEOF</span><span class="special">(</span><span class="char">'{'</span> <span class="special"><<</span> <span class="identifier">karma</span><span class="special">::</span><span class="identifier">double_</span> <span class="special"><<</span> <span class="char">','</span> <span class="special"><<</span> <span class="identifier">karma</span><span class="special">::</span><span class="identifier">double_</span> <span class="special"><<</span> <span class="char">'}'</span><span class="special">)</span> 519 <span class="special">>::</span><span class="identifier">type</span> <span class="identifier">type</span><span class="special">;</span> 520 521 <span class="keyword">static</span> <span class="identifier">type</span> <span class="identifier">call</span><span class="special">()</span> 522 <span class="special">{</span> 523 <span class="keyword">return</span> <span class="identifier">proto</span><span class="special">::</span><span class="identifier">deep_copy</span><span class="special">(</span> 524 <span class="char">'{'</span> <span class="special"><<</span> <span class="identifier">karma</span><span class="special">::</span><span class="identifier">double_</span> <span class="special"><<</span> <span class="char">','</span> <span class="special"><<</span> <span class="identifier">karma</span><span class="special">::</span><span class="identifier">double_</span> <span class="special"><<</span> <span class="char">'}'</span><span class="special">);</span> 525 <span class="special">}</span> 526 <span class="special">};</span> 527<span class="special">}}}</span> 528</pre> 529<p> 530 </p> 531<p> 532 Some usage examples of <code class="computeroutput"><span class="identifier">auto_</span></code> 533 generators: 534 </p> 535<p> 536 Emit a simple string using the <code class="computeroutput"><span class="identifier">karma</span><span class="special">::</span><span class="identifier">string</span></code> 537 generator: 538 </p> 539<p> 540</p> 541<pre class="programlisting"><span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">"abc"</span><span class="special">,</span> <span class="identifier">auto_</span><span class="special">,</span> <span class="string">"abc"</span><span class="special">);</span> 542<span class="identifier">test_generator</span><span class="special">(</span><span class="string">"abc"</span><span class="special">,</span> <span class="identifier">auto_</span><span class="special">(</span><span class="string">"abc"</span><span class="special">));</span> 543</pre> 544<p> 545 </p> 546<p> 547 Emit instances of the <code class="computeroutput"><span class="identifier">complex</span></code> 548 data type as defined above using the generator defined by the customization 549 point for <code class="computeroutput"><span class="identifier">complex</span></code>: 550 </p> 551<p> 552</p> 553<pre class="programlisting"><span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">"{1.2,2.4}"</span><span class="special">,</span> <span class="identifier">auto_</span><span class="special">,</span> <span class="identifier">complex</span><span class="special">(</span><span class="number">1.2</span><span class="special">,</span> <span class="number">2.4</span><span class="special">));</span> 554<span class="identifier">test_generator</span><span class="special">(</span><span class="string">"{1.2,2.4}"</span><span class="special">,</span> <span class="identifier">auto_</span><span class="special">(</span><span class="identifier">complex</span><span class="special">(</span><span class="number">1.2</span><span class="special">,</span> <span class="number">2.4</span><span class="special">)));</span> 555</pre> 556<p> 557 </p> 558</div> 559<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 560<td align="left"></td> 561<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p> 562 Distributed under the Boost Software License, Version 1.0. (See accompanying 563 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>) 564 </p> 565</div></td> 566</tr></table> 567<hr> 568<div class="spirit-nav"> 569<a accesskey="p" href="action.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.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="auxiliary.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 570</div> 571</body> 572</html> 573