1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Compare two Iterator pointing into a Container Attribute for Equality</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="../iterate.html" title="Extract Attribute Values to Generate Output from a Container (Karma)"> 9<link rel="prev" href="deref_iterator.html" title="Dereference the Iterator pointing into a Container Attribute"> 10<link rel="next" href="../string_traits.html" title="Extract a C-Style String to Generate Output from a String Type (Karma)"> 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="deref_iterator.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../iterate.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="../string_traits.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.advanced.customize.iterate.compare_iterators"></a><a class="link" href="compare_iterators.html" title="Compare two Iterator pointing into a Container Attribute for Equality">Compare 28 two Iterator pointing into a Container Attribute for Equality</a> 29</h5></div></div></div> 30<h6> 31<a name="spirit.advanced.customize.iterate.compare_iterators.h0"></a> 32 <span class="phrase"><a name="spirit.advanced.customize.iterate.compare_iterators.compare_iterators"></a></span><a class="link" href="compare_iterators.html#spirit.advanced.customize.iterate.compare_iterators.compare_iterators">compare_iterators</a> 33 </h6> 34<p> 35 The template <code class="computeroutput"><span class="identifier">compare_iterators</span></code> 36 is a type used as an attribute customization point. It is invoked by 37 the <span class="emphasis"><em>Karma</em></span> repetitive generators (such as <a class="link" href="../../../karma/reference/operator/list.html" title="List Generator (a % b)">List 38 (<code class="computeroutput"><span class="special">%</span></code>)</a>, <a class="link" href="../../../karma/reference/operator/kleene.html" title="Kleene Star Generator (*a)">Kleene 39 (unary <code class="computeroutput"><span class="special">*</span></code>)</a>, <a class="link" href="../../../karma/reference/operator/plus.html" title="Plus Generator (+a)">Plus (unary <code class="computeroutput"><span class="special">+</span></code>)</a>, and <a class="link" href="../../../karma/reference/directive/repeat.html" title="Repetition Generator Directive (repeat[])">Repeat</a>) 40 in order to compare the current iterator (returned either from <a class="link" href="begin_container.html" title="Get the Iterator pointing to the Begin of a Container Attribute"><code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">begin_container</span></code></a> or from <a class="link" href="next_iterator.html" title="Increment the Iterator pointing into a Container Attribute"><code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">next_iterator</span></code></a>) with the end 41 iterator (returned from <a class="link" href="end_container.html" title="Get the Iterator pointing to the End of a Container Attribute"><code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">end_container</span></code></a>) in order to find 42 the end of the element sequence to generate output for. 43 </p> 44<h6> 45<a name="spirit.advanced.customize.iterate.compare_iterators.h1"></a> 46 <span class="phrase"><a name="spirit.advanced.customize.iterate.compare_iterators.module_headers"></a></span><a class="link" href="compare_iterators.html#spirit.advanced.customize.iterate.compare_iterators.module_headers">Module 47 Headers</a> 48 </h6> 49<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">home</span><span class="special">/</span><span class="identifier">support</span><span class="special">/</span><span class="identifier">container</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<div class="note"><table border="0" summary="Note"> 55<tr> 56<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> 57<th align="left">Note</th> 58</tr> 59<tr><td align="left" valign="top"><p> 60 This header file does not need to be included directly by any user 61 program as it is normally included by other Spirit header files relying 62 on its content. 63 </p></td></tr> 64</table></div> 65<h6> 66<a name="spirit.advanced.customize.iterate.compare_iterators.h2"></a> 67 <span class="phrase"><a name="spirit.advanced.customize.iterate.compare_iterators.namespace"></a></span><a class="link" href="compare_iterators.html#spirit.advanced.customize.iterate.compare_iterators.namespace">Namespace</a> 68 </h6> 69<div class="informaltable"><table class="table"> 70<colgroup><col></colgroup> 71<thead><tr><th> 72 <p> 73 Name 74 </p> 75 </th></tr></thead> 76<tbody><tr><td> 77 <p> 78 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">traits</span></code> 79 </p> 80 </td></tr></tbody> 81</table></div> 82<h6> 83<a name="spirit.advanced.customize.iterate.compare_iterators.h3"></a> 84 <span class="phrase"><a name="spirit.advanced.customize.iterate.compare_iterators.synopsis"></a></span><a class="link" href="compare_iterators.html#spirit.advanced.customize.iterate.compare_iterators.synopsis">Synopsis</a> 85 </h6> 86<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Enable</span><span class="special">></span> 87<span class="keyword">struct</span> <span class="identifier">compare_iterators</span> 88<span class="special">{</span> 89 <span class="keyword">static</span> <span class="keyword">bool</span> <span class="identifier">call</span><span class="special">(</span><span class="identifier">Iterator</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">it1</span><span class="special">,</span> <span class="identifier">Iterator</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">it2</span><span class="special">);</span> 90<span class="special">};</span> 91</pre> 92<h6> 93<a name="spirit.advanced.customize.iterate.compare_iterators.h4"></a> 94 <span class="phrase"><a name="spirit.advanced.customize.iterate.compare_iterators.template_parameters"></a></span><a class="link" href="compare_iterators.html#spirit.advanced.customize.iterate.compare_iterators.template_parameters">Template 95 parameters</a> 96 </h6> 97<div class="informaltable"><table class="table"> 98<colgroup> 99<col> 100<col> 101<col> 102</colgroup> 103<thead><tr> 104<th> 105 <p> 106 Parameter 107 </p> 108 </th> 109<th> 110 <p> 111 Description 112 </p> 113 </th> 114<th> 115 <p> 116 Default 117 </p> 118 </th> 119</tr></thead> 120<tbody> 121<tr> 122<td> 123 <p> 124 <code class="computeroutput"><span class="identifier">Iterator</span></code> 125 </p> 126 </td> 127<td> 128 <p> 129 The type, <code class="computeroutput"><span class="identifier">Iterator</span></code> 130 of the iterator to dereference. This is the same as the type 131 returned by the customization point <a class="link" href="container_iterator.html" title="Determine the Type of the Iterator of a Container"><code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">container_iterator</span></code></a>. 132 </p> 133 </td> 134<td> 135 <p> 136 none 137 </p> 138 </td> 139</tr> 140<tr> 141<td> 142 <p> 143 <code class="computeroutput"><span class="identifier">Enable</span></code> 144 </p> 145 </td> 146<td> 147 <p> 148 Helper template parameter usable to selectively enable or disable 149 certain specializations of <code class="computeroutput"><span class="identifier">compare_iterators</span></code> 150 utilizing SFINAE (i.e. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">enable_if</span></code> 151 or <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">disable_if</span></code>). 152 </p> 153 </td> 154<td> 155 <p> 156 <code class="computeroutput"><span class="keyword">void</span></code> 157 </p> 158 </td> 159</tr> 160</tbody> 161</table></div> 162<div class="variablelist"> 163<p class="title"><b>Notation</b></p> 164<dl class="variablelist"> 165<dt><span class="term"><code class="computeroutput"><span class="identifier">Iterator</span></code></span></dt> 166<dd><p> 167 An iterator type. 168 </p></dd> 169<dt><span class="term"><code class="computeroutput"><span class="identifier">it1</span></code>, <code class="computeroutput"><span class="identifier">it2</span></code></span></dt> 170<dd><p> 171 Instances of an iterator of type <code class="computeroutput"><span class="identifier">Iterator</span></code>. 172 </p></dd> 173<dt><span class="term"><code class="computeroutput"><span class="identifier">C</span></code></span></dt> 174<dd><p> 175 A container type whose iterator type is <code class="computeroutput"><span class="identifier">Iterator</span></code>. 176 </p></dd> 177</dl> 178</div> 179<h6> 180<a name="spirit.advanced.customize.iterate.compare_iterators.h5"></a> 181 <span class="phrase"><a name="spirit.advanced.customize.iterate.compare_iterators.expression_semantics"></a></span><a class="link" href="compare_iterators.html#spirit.advanced.customize.iterate.compare_iterators.expression_semantics">Expression 182 Semantics</a> 183 </h6> 184<div class="informaltable"><table class="table"> 185<colgroup> 186<col> 187<col> 188</colgroup> 189<thead><tr> 190<th> 191 <p> 192 Expression 193 </p> 194 </th> 195<th> 196 <p> 197 Semantics 198 </p> 199 </th> 200</tr></thead> 201<tbody><tr> 202<td> 203 <p> 204 <code class="computeroutput"><span class="identifier">compare_iterators</span><span class="special"><</span><span class="identifier">Iterator</span><span class="special">>::</span><span class="identifier">call</span><span class="special">(</span><span class="identifier">it1</span><span class="special">,</span> <span class="identifier">it2</span><span class="special">)</span></code> 205 </p> 206 </td> 207<td> 208 <p> 209 Returns whether the iterators <code class="computeroutput"><span class="identifier">it1</span></code> 210 <code class="computeroutput"><span class="identifier">it2</span></code> are to 211 be treated as being equal. 212 </p> 213 </td> 214</tr></tbody> 215</table></div> 216<h6> 217<a name="spirit.advanced.customize.iterate.compare_iterators.h6"></a> 218 <span class="phrase"><a name="spirit.advanced.customize.iterate.compare_iterators.predefined_specializations"></a></span><a class="link" href="compare_iterators.html#spirit.advanced.customize.iterate.compare_iterators.predefined_specializations">Predefined 219 Specializations</a> 220 </h6> 221<p> 222 <a href="http://boost-spirit.com" target="_top">Spirit</a> predefines specializations 223 of this customization point for several types. The following table lists 224 those types together with the types returned by the embedded typedef 225 <code class="computeroutput"><span class="identifier">type</span></code>: 226 </p> 227<div class="informaltable"><table class="table"> 228<colgroup> 229<col> 230<col> 231</colgroup> 232<thead><tr> 233<th> 234 <p> 235 Template Parameters 236 </p> 237 </th> 238<th> 239 <p> 240 Semantics 241 </p> 242 </th> 243</tr></thead> 244<tbody> 245<tr> 246<td> 247 <p> 248 <code class="computeroutput"><span class="identifier">Iterator</span></code> 249 </p> 250 </td> 251<td> 252 <p> 253 The function <code class="computeroutput"><span class="identifier">call</span><span class="special">()</span></code> returns it1 == it2. 254 </p> 255 </td> 256</tr> 257<tr> 258<td> 259 <p> 260 <code class="computeroutput"><span class="identifier">unused_type</span></code><code class="computeroutput"> 261 <span class="keyword">const</span><span class="special">*</span></code> 262 </p> 263 </td> 264<td> 265 <p> 266 The function <code class="computeroutput"><span class="identifier">call</span><span class="special">()</span></code> always returns false. 267 </p> 268 </td> 269</tr> 270</tbody> 271</table></div> 272<h6> 273<a name="spirit.advanced.customize.iterate.compare_iterators.h7"></a> 274 <span class="phrase"><a name="spirit.advanced.customize.iterate.compare_iterators.when_to_implement"></a></span><a class="link" href="compare_iterators.html#spirit.advanced.customize.iterate.compare_iterators.when_to_implement">When 275 to implement</a> 276 </h6> 277<p> 278 The customization point <code class="computeroutput"><span class="identifier">compare_iterators</span></code> 279 needs to be implemented for a specific iterator type whenever the container 280 this iterator belongs to is to be used as an attribute in place of a 281 STL container. It is applicable for generators (<span class="emphasis"><em>Spirit.Karma</em></span>) 282 only. As a rule of thumb: it has to be implemented whenever a certain 283 iterator type belongs to a container which is to be passed as an attribute 284 to a generator normally exposing a STL container, <code class="computeroutput"><span class="identifier">C</span></code> 285 and if the container type does not expose the interface of a STL container 286 (i.e. <code class="computeroutput"><span class="identifier">is_container</span><span class="special"><</span><span class="identifier">C</span><span class="special">>::</span><span class="identifier">type</span></code> would normally return <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">false_</span></code>). 287 </p> 288<h6> 289<a name="spirit.advanced.customize.iterate.compare_iterators.h8"></a> 290 <span class="phrase"><a name="spirit.advanced.customize.iterate.compare_iterators.related_attribute_customization_points"></a></span><a class="link" href="compare_iterators.html#spirit.advanced.customize.iterate.compare_iterators.related_attribute_customization_points">Related 291 Attribute Customization Points</a> 292 </h6> 293<p> 294 If this customization point is implemented, the following other customization 295 points might need to be implemented as well. 296 </p> 297<div class="informaltable"><table class="table"> 298<colgroup> 299<col> 300<col> 301</colgroup> 302<thead><tr> 303<th> 304 <p> 305 Name 306 </p> 307 </th> 308<th> 309 <p> 310 When to implement 311 </p> 312 </th> 313</tr></thead> 314<tbody> 315<tr> 316<td> 317 <p> 318 <a class="link" href="../is_container.html" title="Determine if a Type Should be Treated as a Container (Qi and Karma)"><code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">is_container</span></code></a> 319 </p> 320 </td> 321<td> 322 <p> 323 Needs to be implemented whenever a type is to be used as a 324 container attribute in <span class="emphasis"><em>Karma</em></span>. 325 </p> 326 </td> 327</tr> 328<tr> 329<td> 330 <p> 331 <a class="link" href="container_iterator.html" title="Determine the Type of the Iterator of a Container"><code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">container_iterator</span></code></a> 332 </p> 333 </td> 334<td> 335 <p> 336 Karma: <a class="link" href="../../../karma/reference/operator/list.html" title="List Generator (a % b)">List 337 (<code class="computeroutput"><span class="special">%</span></code>)</a>, <a class="link" href="../../../karma/reference/operator/kleene.html" title="Kleene Star Generator (*a)">Kleene (unary 338 <code class="computeroutput"><span class="special">*</span></code>)</a>, <a class="link" href="../../../karma/reference/operator/plus.html" title="Plus Generator (+a)">Plus (unary 339 <code class="computeroutput"><span class="special">+</span></code>)</a>, <a class="link" href="../../../karma/reference/directive/repeat.html" title="Repetition Generator Directive (repeat[])">Repeat</a>. 340 </p> 341 </td> 342</tr> 343<tr> 344<td> 345 <p> 346 <a class="link" href="begin_container.html" title="Get the Iterator pointing to the Begin of a Container Attribute"><code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">begin_container</span></code></a> 347 </p> 348 </td> 349<td> 350 <p> 351 Karma: <a class="link" href="../../../karma/reference/operator/list.html" title="List Generator (a % b)">List 352 (<code class="computeroutput"><span class="special">%</span></code>)</a>, <a class="link" href="../../../karma/reference/operator/kleene.html" title="Kleene Star Generator (*a)">Kleene (unary 353 <code class="computeroutput"><span class="special">*</span></code>)</a>, <a class="link" href="../../../karma/reference/operator/plus.html" title="Plus Generator (+a)">Plus (unary 354 <code class="computeroutput"><span class="special">+</span></code>)</a>, <a class="link" href="../../../karma/reference/directive/repeat.html" title="Repetition Generator Directive (repeat[])">Repeat</a>. 355 </p> 356 </td> 357</tr> 358<tr> 359<td> 360 <p> 361 <a class="link" href="end_container.html" title="Get the Iterator pointing to the End of a Container Attribute"><code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">end_container</span></code></a> 362 </p> 363 </td> 364<td> 365 <p> 366 Karma: <a class="link" href="../../../karma/reference/operator/list.html" title="List Generator (a % b)">List 367 (<code class="computeroutput"><span class="special">%</span></code>)</a>, <a class="link" href="../../../karma/reference/operator/kleene.html" title="Kleene Star Generator (*a)">Kleene (unary 368 <code class="computeroutput"><span class="special">*</span></code>)</a>, <a class="link" href="../../../karma/reference/operator/plus.html" title="Plus Generator (+a)">Plus (unary 369 <code class="computeroutput"><span class="special">+</span></code>)</a>, <a class="link" href="../../../karma/reference/directive/repeat.html" title="Repetition Generator Directive (repeat[])">Repeat</a>. 370 </p> 371 </td> 372</tr> 373<tr> 374<td> 375 <p> 376 <a class="link" href="deref_iterator.html" title="Dereference the Iterator pointing into a Container Attribute"><code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">deref_iterator</span></code></a> 377 </p> 378 </td> 379<td> 380 <p> 381 Karma: <a class="link" href="../../../karma/reference/operator/list.html" title="List Generator (a % b)">List 382 (<code class="computeroutput"><span class="special">%</span></code>)</a>, <a class="link" href="../../../karma/reference/operator/kleene.html" title="Kleene Star Generator (*a)">Kleene (unary 383 <code class="computeroutput"><span class="special">*</span></code>)</a>, <a class="link" href="../../../karma/reference/operator/plus.html" title="Plus Generator (+a)">Plus (unary 384 <code class="computeroutput"><span class="special">+</span></code>)</a>, <a class="link" href="../../../karma/reference/directive/repeat.html" title="Repetition Generator Directive (repeat[])">Repeat</a>. 385 </p> 386 </td> 387</tr> 388<tr> 389<td> 390 <p> 391 <a class="link" href="next_iterator.html" title="Increment the Iterator pointing into a Container Attribute"><code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">next_iterator</span></code></a> 392 </p> 393 </td> 394<td> 395 <p> 396 Karma: <a class="link" href="../../../karma/reference/operator/list.html" title="List Generator (a % b)">List 397 (<code class="computeroutput"><span class="special">%</span></code>)</a>, <a class="link" href="../../../karma/reference/operator/kleene.html" title="Kleene Star Generator (*a)">Kleene (unary 398 <code class="computeroutput"><span class="special">*</span></code>)</a>, <a class="link" href="../../../karma/reference/operator/plus.html" title="Plus Generator (+a)">Plus (unary 399 <code class="computeroutput"><span class="special">+</span></code>)</a>, <a class="link" href="../../../karma/reference/directive/repeat.html" title="Repetition Generator Directive (repeat[])">Repeat</a>. 400 </p> 401 </td> 402</tr> 403<tr> 404<td> 405 <p> 406 <a class="link" href="compare_iterators.html" title="Compare two Iterator pointing into a Container Attribute for Equality"><code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">compare_iterators</span></code></a> 407 </p> 408 </td> 409<td> 410 <p> 411 Karma: <a class="link" href="../../../karma/reference/operator/list.html" title="List Generator (a % b)">List 412 (<code class="computeroutput"><span class="special">%</span></code>)</a>, <a class="link" href="../../../karma/reference/operator/kleene.html" title="Kleene Star Generator (*a)">Kleene (unary 413 <code class="computeroutput"><span class="special">*</span></code>)</a>, <a class="link" href="../../../karma/reference/operator/plus.html" title="Plus Generator (+a)">Plus (unary 414 <code class="computeroutput"><span class="special">+</span></code>)</a>, <a class="link" href="../../../karma/reference/directive/repeat.html" title="Repetition Generator Directive (repeat[])">Repeat</a>. 415 </p> 416 </td> 417</tr> 418</tbody> 419</table></div> 420<h6> 421<a name="spirit.advanced.customize.iterate.compare_iterators.h9"></a> 422 <span class="phrase"><a name="spirit.advanced.customize.iterate.compare_iterators.example"></a></span><a class="link" href="compare_iterators.html#spirit.advanced.customize.iterate.compare_iterators.example">Example</a> 423 </h6> 424<p> 425 For an example of how to use the customization point <code class="computeroutput"><span class="identifier">compare_iterators</span></code> 426 please see here: <a class="link" href="next_iterator.html#spirit.advanced.customize.iterate.next_iterator.example">use_as_container</a>. 427 </p> 428</div> 429<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 430<td align="left"></td> 431<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p> 432 Distributed under the Boost Software License, Version 1.0. (See accompanying 433 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>) 434 </p> 435</div></td> 436</tr></table> 437<hr> 438<div class="spirit-nav"> 439<a accesskey="p" href="deref_iterator.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../iterate.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="../string_traits.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 440</div> 441</body> 442</html> 443