PageRenderTime 68ms CodeModel.GetById 26ms app.highlight 30ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/libs/iterator/doc/iterator_facade.html

http://hadesmem.googlecode.com/
HTML | 1348 lines | 1259 code | 62 blank | 27 comment | 0 complexity | 52ca6966e55f88bc79ecded6ddd4ccb4 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1<?xml version="1.0" encoding="utf-8" ?>
  2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4<head>
  5<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
  7<title>Iterator Facade</title>
  8<meta name="author" content="David Abrahams, Jeremy Siek, Thomas Witt" />
  9<meta name="organization" content="Boost Consulting, Indiana University Open Systems Lab, University of Hanover Institute for Transport Railway Operation and Construction" />
 10<meta name="date" content="2006-09-11" />
 11<meta name="copyright" content="Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003." />
 12<link rel="stylesheet" href="../../../rst.css" type="text/css" />
 13</head>
 14<body>
 15<div class="document" id="iterator-facade">
 16<h1 class="title">Iterator Facade</h1>
 17<table class="docinfo" frame="void" rules="none">
 18<col class="docinfo-name" />
 19<col class="docinfo-content" />
 20<tbody valign="top">
 21<tr><th class="docinfo-name">Author:</th>
 22<td>David Abrahams, Jeremy Siek, Thomas Witt</td></tr>
 23<tr><th class="docinfo-name">Contact:</th>
 24<td><a class="first reference external" href="mailto:dave&#64;boost-consulting.com">dave&#64;boost-consulting.com</a>, <a class="reference external" href="mailto:jsiek&#64;osl.iu.edu">jsiek&#64;osl.iu.edu</a>, <a class="last reference external" href="mailto:witt&#64;ive.uni-hannover.de">witt&#64;ive.uni-hannover.de</a></td></tr>
 25<tr><th class="docinfo-name">Organization:</th>
 26<td><a class="first reference external" href="http://www.boost-consulting.com">Boost Consulting</a>, Indiana University <a class="reference external" href="http://www.osl.iu.edu">Open Systems
 27Lab</a>, University of Hanover <a class="last reference external" href="http://www.ive.uni-hannover.de">Institute for Transport
 28Railway Operation and Construction</a></td></tr>
 29<tr><th class="docinfo-name">Date:</th>
 30<td>2006-09-11</td></tr>
 31<tr><th class="docinfo-name">Copyright:</th>
 32<td>Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003.</td></tr>
 33</tbody>
 34</table>
 35<!-- Distributed under the Boost -->
 36<!-- Software License, Version 1.0. (See accompanying -->
 37<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
 38<table class="docutils field-list" frame="void" rules="none">
 39<col class="field-name" />
 40<col class="field-body" />
 41<tbody valign="top">
 42<tr class="field"><th class="field-name">abstract:</th><td class="field-body"><!-- Copyright David Abrahams 2006. Distributed under the Boost -->
 43<!-- Software License, Version 1.0. (See accompanying -->
 44<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
 45<tt class="docutils literal"><span class="pre">iterator_facade</span></tt> is a base class template that implements the
 46interface of standard iterators in terms of a few core functions
 47and associated types, to be supplied by a derived iterator class.</td>
 48</tr>
 49</tbody>
 50</table>
 51<div class="contents topic" id="table-of-contents">
 52<p class="topic-title first">Table of Contents</p>
 53<ul class="simple">
 54<li><a class="reference internal" href="#overview" id="id23">Overview</a><ul>
 55<li><a class="reference internal" href="#usage" id="id24">Usage</a></li>
 56<li><a class="reference internal" href="#iterator-core-access" id="id25">Iterator Core Access</a></li>
 57<li><a class="reference internal" href="#operator" id="id26"><tt class="docutils literal"><span class="pre">operator[]</span></tt></a></li>
 58<li><a class="reference internal" href="#id2" id="id27"><tt class="docutils literal"><span class="pre">operator-&gt;</span></tt></a></li>
 59</ul>
 60</li>
 61<li><a class="reference internal" href="#reference" id="id28">Reference</a><ul>
 62<li><a class="reference internal" href="#iterator-facade-requirements" id="id29"><tt class="docutils literal"><span class="pre">iterator_facade</span></tt> Requirements</a></li>
 63<li><a class="reference internal" href="#iterator-facade-operations" id="id30"><tt class="docutils literal"><span class="pre">iterator_facade</span></tt> operations</a></li>
 64</ul>
 65</li>
 66<li><a class="reference internal" href="#tutorial-example" id="id31">Tutorial Example</a><ul>
 67<li><a class="reference internal" href="#the-problem" id="id32">The Problem</a></li>
 68<li><a class="reference internal" href="#a-basic-iterator-using-iterator-facade" id="id33">A Basic Iterator Using <tt class="docutils literal"><span class="pre">iterator_facade</span></tt></a><ul>
 69<li><a class="reference internal" href="#template-arguments-for-iterator-facade" id="id34">Template Arguments for <tt class="docutils literal"><span class="pre">iterator_facade</span></tt></a><ul>
 70<li><a class="reference internal" href="#derived" id="id35"><tt class="docutils literal"><span class="pre">Derived</span></tt></a></li>
 71<li><a class="reference internal" href="#value" id="id36"><tt class="docutils literal"><span class="pre">Value</span></tt></a></li>
 72<li><a class="reference internal" href="#categoryortraversal" id="id37"><tt class="docutils literal"><span class="pre">CategoryOrTraversal</span></tt></a></li>
 73<li><a class="reference internal" href="#id12" id="id38"><tt class="docutils literal"><span class="pre">Reference</span></tt></a></li>
 74<li><a class="reference internal" href="#difference" id="id39"><tt class="docutils literal"><span class="pre">Difference</span></tt></a></li>
 75</ul>
 76</li>
 77<li><a class="reference internal" href="#constructors-and-data-members" id="id40">Constructors and Data Members</a></li>
 78<li><a class="reference internal" href="#implementing-the-core-operations" id="id41">Implementing the Core Operations</a></li>
 79</ul>
 80</li>
 81<li><a class="reference internal" href="#a-constant-node-iterator" id="id42">A constant <tt class="docutils literal"><span class="pre">node_iterator</span></tt></a></li>
 82<li><a class="reference internal" href="#interoperability" id="id43">Interoperability</a></li>
 83<li><a class="reference internal" href="#telling-the-truth" id="id44">Telling the Truth</a></li>
 84<li><a class="reference internal" href="#wrap-up" id="id45">Wrap Up</a></li>
 85</ul>
 86</li>
 87</ul>
 88</div>
 89<div class="section" id="overview">
 90<h1><a class="toc-backref" href="#id23">Overview</a></h1>
 91<!-- Distributed under the Boost -->
 92<!-- Software License, Version 1.0. (See accompanying -->
 93<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
 94<!-- Version 1.1 of this ReStructuredText document corresponds to
 95n1530_, the paper accepted by the LWG for TR1. -->
 96<!-- Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. -->
 97<p>While the iterator interface is rich, there is a core subset of the
 98interface that is necessary for all the functionality.  We have
 99identified the following core behaviors for iterators:</p>
100<ul class="simple">
101<li>dereferencing</li>
102<li>incrementing</li>
103<li>decrementing</li>
104<li>equality comparison</li>
105<li>random-access motion</li>
106<li>distance measurement</li>
107</ul>
108<p>In addition to the behaviors listed above, the core interface elements
109include the associated types exposed through iterator traits:
110<tt class="docutils literal"><span class="pre">value_type</span></tt>, <tt class="docutils literal"><span class="pre">reference</span></tt>, <tt class="docutils literal"><span class="pre">difference_type</span></tt>, and
111<tt class="docutils literal"><span class="pre">iterator_category</span></tt>.</p>
112<p>Iterator facade uses the Curiously Recurring Template
113Pattern (CRTP) <a class="citation-reference" href="#cop95" id="id1">[Cop95]</a> so that the user can specify the behavior
114of <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> in a derived class.  Former designs used
115policy objects to specify the behavior, but that approach was
116discarded for several reasons:</p>
117<blockquote>
118<ol class="arabic simple">
119<li>the creation and eventual copying of the policy object may create
120overhead that can be avoided with the current approach.</li>
121<li>The policy object approach does not allow for custom constructors
122on the created iterator types, an essential feature if
123<tt class="docutils literal"><span class="pre">iterator_facade</span></tt> should be used in other library
124implementations.</li>
125<li>Without the use of CRTP, the standard requirement that an
126iterator's <tt class="docutils literal"><span class="pre">operator++</span></tt> returns the iterator type itself
127would mean that all iterators built with the library would
128have to be specializations of <tt class="docutils literal"><span class="pre">iterator_facade&lt;...&gt;</span></tt>, rather
129than something more descriptive like
130<tt class="docutils literal"><span class="pre">indirect_iterator&lt;T*&gt;</span></tt>.  Cumbersome type generator
131metafunctions would be needed to build new parameterized
132iterators, and a separate <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> layer would be
133impossible.</li>
134</ol>
135</blockquote>
136<div class="section" id="usage">
137<h2><a class="toc-backref" href="#id24">Usage</a></h2>
138<p>The user of <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> derives his iterator class from a
139specialization of <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> and passes the derived
140iterator class as <tt class="docutils literal"><span class="pre">iterator_facade</span></tt>'s first template parameter.
141The order of the other template parameters have been carefully
142chosen to take advantage of useful defaults.  For example, when
143defining a constant lvalue iterator, the user can pass a
144const-qualified version of the iterator's <tt class="docutils literal"><span class="pre">value_type</span></tt> as
145<tt class="docutils literal"><span class="pre">iterator_facade</span></tt>'s <tt class="docutils literal"><span class="pre">Value</span></tt> parameter and omit the
146<tt class="docutils literal"><span class="pre">Reference</span></tt> parameter which follows.</p>
147<p>The derived iterator class must define member functions implementing
148the iterator's core behaviors.  The following table describes
149expressions which are required to be valid depending on the category
150of the derived iterator type.  These member functions are described
151briefly below and in more detail in the iterator facade
152requirements.</p>
153<blockquote>
154<table border="1" class="docutils">
155<colgroup>
156<col width="44%" />
157<col width="56%" />
158</colgroup>
159<thead valign="bottom">
160<tr><th class="head">Expression</th>
161<th class="head">Effects</th>
162</tr>
163</thead>
164<tbody valign="top">
165<tr><td><tt class="docutils literal"><span class="pre">i.dereference()</span></tt></td>
166<td>Access the value referred to</td>
167</tr>
168<tr><td><tt class="docutils literal"><span class="pre">i.equal(j)</span></tt></td>
169<td>Compare for equality with <tt class="docutils literal"><span class="pre">j</span></tt></td>
170</tr>
171<tr><td><tt class="docutils literal"><span class="pre">i.increment()</span></tt></td>
172<td>Advance by one position</td>
173</tr>
174<tr><td><tt class="docutils literal"><span class="pre">i.decrement()</span></tt></td>
175<td>Retreat by one position</td>
176</tr>
177<tr><td><tt class="docutils literal"><span class="pre">i.advance(n)</span></tt></td>
178<td>Advance by <tt class="docutils literal"><span class="pre">n</span></tt> positions</td>
179</tr>
180<tr><td><tt class="docutils literal"><span class="pre">i.distance_to(j)</span></tt></td>
181<td>Measure the distance to <tt class="docutils literal"><span class="pre">j</span></tt></td>
182</tr>
183</tbody>
184</table>
185</blockquote>
186<!-- Should we add a comment that a zero overhead implementation of iterator_facade
187is possible with proper inlining? -->
188<p>In addition to implementing the core interface functions, an iterator
189derived from <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> typically defines several
190constructors. To model any of the standard iterator concepts, the
191iterator must at least have a copy constructor. Also, if the iterator
192type <tt class="docutils literal"><span class="pre">X</span></tt> is meant to be automatically interoperate with another
193iterator type <tt class="docutils literal"><span class="pre">Y</span></tt> (as with constant and mutable iterators) then
194there must be an implicit conversion from <tt class="docutils literal"><span class="pre">X</span></tt> to <tt class="docutils literal"><span class="pre">Y</span></tt> or from <tt class="docutils literal"><span class="pre">Y</span></tt>
195to <tt class="docutils literal"><span class="pre">X</span></tt> (but not both), typically implemented as a conversion
196constructor. Finally, if the iterator is to model Forward Traversal
197Iterator or a more-refined iterator concept, a default constructor is
198required.</p>
199</div>
200<div class="section" id="iterator-core-access">
201<h2><a class="toc-backref" href="#id25">Iterator Core Access</a></h2>
202<p><tt class="docutils literal"><span class="pre">iterator_facade</span></tt> and the operator implementations need to be able
203to access the core member functions in the derived class.  Making the
204core member functions public would expose an implementation detail to
205the user.  The design used here ensures that implementation details do
206not appear in the public interface of the derived iterator type.</p>
207<p>Preventing direct access to the core member functions has two
208advantages.  First, there is no possibility for the user to accidently
209use a member function of the iterator when a member of the value_type
210was intended.  This has been an issue with smart pointer
211implementations in the past.  The second and main advantage is that
212library implementers can freely exchange a hand-rolled iterator
213implementation for one based on <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> without fear of
214breaking code that was accessing the public core member functions
215directly.</p>
216<p>In a naive implementation, keeping the derived class' core member
217functions private would require it to grant friendship to
218<tt class="docutils literal"><span class="pre">iterator_facade</span></tt> and each of the seven operators.  In order to
219reduce the burden of limiting access, <tt class="docutils literal"><span class="pre">iterator_core_access</span></tt> is
220provided, a class that acts as a gateway to the core member functions
221in the derived iterator class.  The author of the derived class only
222needs to grant friendship to <tt class="docutils literal"><span class="pre">iterator_core_access</span></tt> to make his core
223member functions available to the library.</p>
224<!-- This is no long uptodate -thw -->
225<!-- Yes it is; I made sure of it! -DWA -->
226<p><tt class="docutils literal"><span class="pre">iterator_core_access</span></tt> will be typically implemented as an empty
227class containing only private static member functions which invoke the
228iterator core member functions. There is, however, no need to
229standardize the gateway protocol.  Note that even if
230<tt class="docutils literal"><span class="pre">iterator_core_access</span></tt> used public member functions it would not
231open a safety loophole, as every core member function preserves the
232invariants of the iterator.</p>
233</div>
234<div class="section" id="operator">
235<h2><a class="toc-backref" href="#id26"><tt class="docutils literal"><span class="pre">operator[]</span></tt></a></h2>
236<p>The indexing operator for a generalized iterator presents special
237challenges.  A random access iterator's <tt class="docutils literal"><span class="pre">operator[]</span></tt> is only
238required to return something convertible to its <tt class="docutils literal"><span class="pre">value_type</span></tt>.
239Requiring that it return an lvalue would rule out currently-legal
240random-access iterators which hold the referenced value in a data
241member (e.g. <a class="reference external" href="counting_iterator.html"><tt class="docutils literal"><span class="pre">counting_iterator</span></tt></a>), because <tt class="docutils literal"><span class="pre">*(p+n)</span></tt> is a reference
242into the temporary iterator <tt class="docutils literal"><span class="pre">p+n</span></tt>, which is destroyed when
243<tt class="docutils literal"><span class="pre">operator[]</span></tt> returns.</p>
244<p>Writable iterators built with <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> implement the
245semantics required by the preferred resolution to <a class="reference external" href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#299">issue 299</a> and
246adopted by proposal <a class="reference external" href="http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/papers/2003/n1550.html">n1550</a>: the result of <tt class="docutils literal"><span class="pre">p[n]</span></tt> is an object
247convertible to the iterator's <tt class="docutils literal"><span class="pre">value_type</span></tt>, and <tt class="docutils literal"><span class="pre">p[n]</span> <span class="pre">=</span> <span class="pre">x</span></tt> is
248equivalent to <tt class="docutils literal"><span class="pre">*(p</span> <span class="pre">+</span> <span class="pre">n)</span> <span class="pre">=</span> <span class="pre">x</span></tt> (Note: This result object may be
249implemented as a proxy containing a copy of <tt class="docutils literal"><span class="pre">p+n</span></tt>).  This approach
250will work properly for any random-access iterator regardless of the
251other details of its implementation.  A user who knows more about
252the implementation of her iterator is free to implement an
253<tt class="docutils literal"><span class="pre">operator[]</span></tt> that returns an lvalue in the derived iterator
254class; it will hide the one supplied by <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> from
255clients of her iterator.</p>
256</div>
257<div class="section" id="id2">
258<span id="operator-arrow"></span><h2><a class="toc-backref" href="#id27"><tt class="docutils literal"><span class="pre">operator-&gt;</span></tt></a></h2>
259<p>The <tt class="docutils literal"><span class="pre">reference</span></tt> type of a readable iterator (and today's input
260iterator) need not in fact be a reference, so long as it is
261convertible to the iterator's <tt class="docutils literal"><span class="pre">value_type</span></tt>.  When the <tt class="docutils literal"><span class="pre">value_type</span></tt>
262is a class, however, it must still be possible to access members
263through <tt class="docutils literal"><span class="pre">operator-&gt;</span></tt>.  Therefore, an iterator whose <tt class="docutils literal"><span class="pre">reference</span></tt>
264type is not in fact a reference must return a proxy containing a copy
265of the referenced value from its <tt class="docutils literal"><span class="pre">operator-&gt;</span></tt>.</p>
266<p>The return types for <tt class="docutils literal"><span class="pre">iterator_facade</span></tt>'s <tt class="docutils literal"><span class="pre">operator-&gt;</span></tt> and
267<tt class="docutils literal"><span class="pre">operator[]</span></tt> are not explicitly specified. Instead, those types
268are described in terms of a set of requirements, which must be
269satisfied by the <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> implementation.</p>
270<table class="docutils citation" frame="void" id="cop95" rules="none">
271<colgroup><col class="label" /><col /></colgroup>
272<tbody valign="top">
273<tr><td class="label">[Cop95]</td><td><em>(<a class="fn-backref" href="#id1">1</a>, <a class="fn-backref" href="#id10">2</a>)</em> [Coplien, 1995] Coplien, J., Curiously Recurring Template
274Patterns, C++ Report, February 1995, pp. 24-27.</td></tr>
275</tbody>
276</table>
277</div>
278</div>
279<div class="section" id="reference">
280<h1><a class="toc-backref" href="#id28">Reference</a></h1>
281<!-- Distributed under the Boost -->
282<!-- Software License, Version 1.0. (See accompanying -->
283<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
284<!-- Version 1.3 of this ReStructuredText document corresponds to
285n1530_, the paper accepted by the LWG for TR1. -->
286<!-- Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. -->
287<pre class="literal-block">
288template &lt;
289    class Derived
290  , class Value
291  , class CategoryOrTraversal
292  , class Reference  = Value&amp;
293  , class Difference = ptrdiff_t
294&gt;
295class iterator_facade {
296 public:
297    typedef remove_const&lt;Value&gt;::type value_type;
298    typedef Reference reference;
299    typedef Value* pointer;
300    typedef Difference difference_type;
301    typedef /* see <a class="reference internal" href="#iterator-category">below</a> */ iterator_category;
302
303    reference operator*() const;
304    /* see <a class="reference internal" href="#operator-arrow">below</a> */ operator-&gt;() const;
305    /* see <a class="reference internal" href="#brackets">below</a> */ operator[](difference_type n) const;
306    Derived&amp; operator++();
307    Derived operator++(int);
308    Derived&amp; operator--();
309    Derived operator--(int);
310    Derived&amp; operator+=(difference_type n);
311    Derived&amp; operator-=(difference_type n);
312    Derived operator-(difference_type n) const;
313 protected:
314    typedef iterator_facade iterator_facade_;
315};
316
317// Comparison operators
318template &lt;class Dr1, class V1, class TC1, class R1, class D1,
319          class Dr2, class V2, class TC2, class R2, class D2&gt;
320typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type // exposition
321operator ==(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
322            iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
323
324template &lt;class Dr1, class V1, class TC1, class R1, class D1,
325          class Dr2, class V2, class TC2, class R2, class D2&gt;
326typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
327operator !=(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
328            iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
329
330template &lt;class Dr1, class V1, class TC1, class R1, class D1,
331          class Dr2, class V2, class TC2, class R2, class D2&gt;
332typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
333operator &lt;(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
334           iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
335
336template &lt;class Dr1, class V1, class TC1, class R1, class D1,
337          class Dr2, class V2, class TC2, class R2, class D2&gt;
338typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
339operator &lt;=(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
340            iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
341
342template &lt;class Dr1, class V1, class TC1, class R1, class D1,
343          class Dr2, class V2, class TC2, class R2, class D2&gt;
344typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
345operator &gt;(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
346           iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
347
348template &lt;class Dr1, class V1, class TC1, class R1, class D1,
349          class Dr2, class V2, class TC2, class R2, class D2&gt;
350typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
351operator &gt;=(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
352            iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
353
354// Iterator difference
355template &lt;class Dr1, class V1, class TC1, class R1, class D1,
356          class Dr2, class V2, class TC2, class R2, class D2&gt;
357/* see <a class="reference internal" href="#minus">below</a> */
358operator-(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
359          iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
360
361// Iterator addition
362template &lt;class Dr, class V, class TC, class R, class D&gt;
363Derived operator+ (iterator_facade&lt;Dr,V,TC,R,D&gt; const&amp;,
364                   typename Derived::difference_type n);
365
366template &lt;class Dr, class V, class TC, class R, class D&gt;
367Derived operator+ (typename Derived::difference_type n,
368                   iterator_facade&lt;Dr,V,TC,R,D&gt; const&amp;);
369</pre>
370<p id="iterator-category">The <tt class="docutils literal"><span class="pre">iterator_category</span></tt> member of <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> is</p>
371<pre class="literal-block">
372<em>iterator-category</em>(CategoryOrTraversal, value_type, reference)
373</pre>
374<p>where <em>iterator-category</em> is defined as follows:</p>
375<pre class="literal-block" id="id7">
376<em>iterator-category</em>(C,R,V) :=
377   if (C is convertible to std::input_iterator_tag
378       || C is convertible to std::output_iterator_tag
379   )
380       return C
381
382   else if (C is not convertible to incrementable_traversal_tag)
383       <em>the program is ill-formed</em>
384
385   else return a type X satisfying the following two constraints:
386
387      1. X is convertible to X1, and not to any more-derived
388         type, where X1 is defined by:
389
390           if (R is a reference type
391               &amp;&amp; C is convertible to forward_traversal_tag)
392           {
393               if (C is convertible to random_access_traversal_tag)
394                   X1 = random_access_iterator_tag
395               else if (C is convertible to bidirectional_traversal_tag)
396                   X1 = bidirectional_iterator_tag
397               else
398                   X1 = forward_iterator_tag
399           }
400           else
401           {
402               if (C is convertible to single_pass_traversal_tag
403                   &amp;&amp; R is convertible to V)
404                   X1 = input_iterator_tag
405               else
406                   X1 = C
407           }
408
409      2. <a class="reference external" href="new-iter-concepts.html#category-to-traversal"><em>category-to-traversal</em></a>(X) is convertible to the most
410         derived traversal tag type to which X is also
411         convertible, and not to any more-derived traversal tag
412         type.
413</pre>
414<p>[Note: the intention is to allow <tt class="docutils literal"><span class="pre">iterator_category</span></tt> to be one of
415the five original category tags when convertibility to one of the
416traversal tags would add no information]</p>
417<!-- Copyright David Abrahams 2004. Use, modification and distribution is -->
418<!-- subject to the Boost Software License, Version 1.0. (See accompanying -->
419<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
420<p>The <tt class="docutils literal"><span class="pre">enable_if_interoperable</span></tt> template used above is for exposition
421purposes.  The member operators should only be in an overload set
422provided the derived types <tt class="docutils literal"><span class="pre">Dr1</span></tt> and <tt class="docutils literal"><span class="pre">Dr2</span></tt> are interoperable,
423meaning that at least one of the types is convertible to the other.  The
424<tt class="docutils literal"><span class="pre">enable_if_interoperable</span></tt> approach uses SFINAE to take the operators
425out of the overload set when the types are not interoperable.
426The operators should behave <em>as-if</em> <tt class="docutils literal"><span class="pre">enable_if_interoperable</span></tt>
427were defined to be:</p>
428<pre class="literal-block">
429template &lt;bool, typename&gt; enable_if_interoperable_impl
430{};
431
432template &lt;typename T&gt; enable_if_interoperable_impl&lt;true,T&gt;
433{ typedef T type; };
434
435template&lt;typename Dr1, typename Dr2, typename T&gt;
436struct enable_if_interoperable
437  : enable_if_interoperable_impl&lt;
438        is_convertible&lt;Dr1,Dr2&gt;::value || is_convertible&lt;Dr2,Dr1&gt;::value
439      , T
440    &gt;
441{};
442</pre>
443<div class="section" id="iterator-facade-requirements">
444<h2><a class="toc-backref" href="#id29"><tt class="docutils literal"><span class="pre">iterator_facade</span></tt> Requirements</a></h2>
445<p>The following table describes the typical valid expressions on
446<tt class="docutils literal"><span class="pre">iterator_facade</span></tt>'s <tt class="docutils literal"><span class="pre">Derived</span></tt> parameter, depending on the
447iterator concept(s) it will model.  The operations in the first
448column must be made accessible to member functions of class
449<tt class="docutils literal"><span class="pre">iterator_core_access</span></tt>.  In addition,
450<tt class="docutils literal"><span class="pre">static_cast&lt;Derived*&gt;(iterator_facade*)</span></tt> shall be well-formed.</p>
451<p>In the table below, <tt class="docutils literal"><span class="pre">F</span></tt> is <tt class="docutils literal"><span class="pre">iterator_facade&lt;X,V,C,R,D&gt;</span></tt>, <tt class="docutils literal"><span class="pre">a</span></tt> is an
452object of type <tt class="docutils literal"><span class="pre">X</span></tt>, <tt class="docutils literal"><span class="pre">b</span></tt> and <tt class="docutils literal"><span class="pre">c</span></tt> are objects of type <tt class="docutils literal"><span class="pre">const</span> <span class="pre">X</span></tt>,
453<tt class="docutils literal"><span class="pre">n</span></tt> is an object of <tt class="docutils literal"><span class="pre">F::difference_type</span></tt>, <tt class="docutils literal"><span class="pre">y</span></tt> is a constant
454object of a single pass iterator type interoperable with <tt class="docutils literal"><span class="pre">X</span></tt>, and <tt class="docutils literal"><span class="pre">z</span></tt>
455is a constant object of a random access traversal iterator type
456interoperable with <tt class="docutils literal"><span class="pre">X</span></tt>.</p>
457<div class="topic" id="core-operations">
458<p class="topic-title first"><tt class="docutils literal"><span class="pre">iterator_facade</span></tt> Core Operations</p>
459<table border="1" class="docutils">
460<colgroup>
461<col width="21%" />
462<col width="23%" />
463<col width="27%" />
464<col width="29%" />
465</colgroup>
466<thead valign="bottom">
467<tr><th class="head">Expression</th>
468<th class="head">Return Type</th>
469<th class="head">Assertion/Note</th>
470<th class="head">Used to implement Iterator
471Concept(s)</th>
472</tr>
473</thead>
474<tbody valign="top">
475<tr><td><tt class="docutils literal"><span class="pre">c.dereference()</span></tt></td>
476<td><tt class="docutils literal"><span class="pre">F::reference</span></tt></td>
477<td>&nbsp;</td>
478<td>Readable Iterator, Writable
479Iterator</td>
480</tr>
481<tr><td><tt class="docutils literal"><span class="pre">c.equal(y)</span></tt></td>
482<td>convertible to bool</td>
483<td>true iff <tt class="docutils literal"><span class="pre">c</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt>
484refer to the same
485position.</td>
486<td>Single Pass Iterator</td>
487</tr>
488<tr><td><tt class="docutils literal"><span class="pre">a.increment()</span></tt></td>
489<td>unused</td>
490<td>&nbsp;</td>
491<td>Incrementable Iterator</td>
492</tr>
493<tr><td><tt class="docutils literal"><span class="pre">a.decrement()</span></tt></td>
494<td>unused</td>
495<td>&nbsp;</td>
496<td>Bidirectional Traversal
497Iterator</td>
498</tr>
499<tr><td><tt class="docutils literal"><span class="pre">a.advance(n)</span></tt></td>
500<td>unused</td>
501<td>&nbsp;</td>
502<td>Random Access Traversal
503Iterator</td>
504</tr>
505<tr><td><tt class="docutils literal"><span class="pre">c.distance_to(z)</span></tt></td>
506<td>convertible to
507<tt class="docutils literal"><span class="pre">F::difference_type</span></tt></td>
508<td>equivalent to
509<tt class="docutils literal"><span class="pre">distance(c,</span> <span class="pre">X(z))</span></tt>.</td>
510<td>Random Access Traversal
511Iterator</td>
512</tr>
513</tbody>
514</table>
515</div>
516</div>
517<div class="section" id="iterator-facade-operations">
518<h2><a class="toc-backref" href="#id30"><tt class="docutils literal"><span class="pre">iterator_facade</span></tt> operations</a></h2>
519<p>The operations in this section are described in terms of operations on
520the core interface of <tt class="docutils literal"><span class="pre">Derived</span></tt> which may be inaccessible
521(i.e. private).  The implementation should access these operations
522through member functions of class <tt class="docutils literal"><span class="pre">iterator_core_access</span></tt>.</p>
523<p><tt class="docutils literal"><span class="pre">reference</span> <span class="pre">operator*()</span> <span class="pre">const;</span></tt></p>
524<table class="docutils field-list" frame="void" rules="none">
525<col class="field-name" />
526<col class="field-body" />
527<tbody valign="top">
528<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">static_cast&lt;Derived</span> <span class="pre">const*&gt;(this)-&gt;dereference()</span></tt></td>
529</tr>
530</tbody>
531</table>
532<p><tt class="docutils literal"><span class="pre">operator-&gt;()</span> <span class="pre">const;</span></tt> (see <a class="reference internal" href="#operator-arrow">below</a>)</p>
533<table class="docutils field-list" frame="void" rules="none">
534<col class="field-name" />
535<col class="field-body" />
536<tbody valign="top">
537<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">If <tt class="docutils literal"><span class="pre">reference</span></tt> is a reference type, an object
538of type <tt class="docutils literal"><span class="pre">pointer</span></tt> equal to:</p>
539<pre class="literal-block">
540&amp;static_cast&lt;Derived const*&gt;(this)-&gt;dereference()
541</pre>
542<p class="last">Otherwise returns an object of unspecified type such that,
543<tt class="docutils literal"><span class="pre">(*static_cast&lt;Derived</span> <span class="pre">const*&gt;(this))-&gt;m</span></tt> is equivalent to <tt class="docutils literal"><span class="pre">(w</span> <span class="pre">=</span> <span class="pre">**static_cast&lt;Derived</span> <span class="pre">const*&gt;(this),</span>
544<span class="pre">w.m)</span></tt> for some temporary object <tt class="docutils literal"><span class="pre">w</span></tt> of type <tt class="docutils literal"><span class="pre">value_type</span></tt>.</p>
545</td>
546</tr>
547</tbody>
548</table>
549<p id="brackets"><em>unspecified</em> <tt class="docutils literal"><span class="pre">operator[](difference_type</span> <span class="pre">n)</span> <span class="pre">const;</span></tt></p>
550<table class="docutils field-list" frame="void" rules="none">
551<col class="field-name" />
552<col class="field-body" />
553<tbody valign="top">
554<tr class="field"><th class="field-name">Returns:</th><td class="field-body">an object convertible to <tt class="docutils literal"><span class="pre">value_type</span></tt>. For constant
555objects <tt class="docutils literal"><span class="pre">v</span></tt> of type <tt class="docutils literal"><span class="pre">value_type</span></tt>, and <tt class="docutils literal"><span class="pre">n</span></tt> of type
556<tt class="docutils literal"><span class="pre">difference_type</span></tt>, <tt class="docutils literal"><span class="pre">(*this)[n]</span> <span class="pre">=</span> <span class="pre">v</span></tt> is equivalent to
557<tt class="docutils literal"><span class="pre">*(*this</span> <span class="pre">+</span> <span class="pre">n)</span> <span class="pre">=</span> <span class="pre">v</span></tt>, and <tt class="docutils literal"><span class="pre">static_cast&lt;value_type</span>
558<span class="pre">const&amp;&gt;((*this)[n])</span></tt> is equivalent to
559<tt class="docutils literal"><span class="pre">static_cast&lt;value_type</span> <span class="pre">const&amp;&gt;(*(*this</span> <span class="pre">+</span> <span class="pre">n))</span></tt></td>
560</tr>
561</tbody>
562</table>
563<p><tt class="docutils literal"><span class="pre">Derived&amp;</span> <span class="pre">operator++();</span></tt></p>
564<table class="docutils field-list" frame="void" rules="none">
565<col class="field-name" />
566<col class="field-body" />
567<tbody valign="top">
568<tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
569static_cast&lt;Derived*&gt;(this)-&gt;increment();
570return *static_cast&lt;Derived*&gt;(this);
571</pre>
572</td>
573</tr>
574</tbody>
575</table>
576<p><tt class="docutils literal"><span class="pre">Derived</span> <span class="pre">operator++(int);</span></tt></p>
577<table class="docutils field-list" frame="void" rules="none">
578<col class="field-name" />
579<col class="field-body" />
580<tbody valign="top">
581<tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
582Derived tmp(static_cast&lt;Derived const*&gt;(this));
583++*this;
584return tmp;
585</pre>
586</td>
587</tr>
588</tbody>
589</table>
590<p><tt class="docutils literal"><span class="pre">Derived&amp;</span> <span class="pre">operator--();</span></tt></p>
591<table class="docutils field-list" frame="void" rules="none">
592<col class="field-name" />
593<col class="field-body" />
594<tbody valign="top">
595<tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
596static_cast&lt;Derived*&gt;(this)-&gt;decrement();
597return *static_cast&lt;Derived*&gt;(this);
598</pre>
599</td>
600</tr>
601</tbody>
602</table>
603<p><tt class="docutils literal"><span class="pre">Derived</span> <span class="pre">operator--(int);</span></tt></p>
604<table class="docutils field-list" frame="void" rules="none">
605<col class="field-name" />
606<col class="field-body" />
607<tbody valign="top">
608<tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
609Derived tmp(static_cast&lt;Derived const*&gt;(this));
610--*this;
611return tmp;
612</pre>
613</td>
614</tr>
615</tbody>
616</table>
617<p><tt class="docutils literal"><span class="pre">Derived&amp;</span> <span class="pre">operator+=(difference_type</span> <span class="pre">n);</span></tt></p>
618<table class="docutils field-list" frame="void" rules="none">
619<col class="field-name" />
620<col class="field-body" />
621<tbody valign="top">
622<tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
623static_cast&lt;Derived*&gt;(this)-&gt;advance(n);
624return *static_cast&lt;Derived*&gt;(this);
625</pre>
626</td>
627</tr>
628</tbody>
629</table>
630<p><tt class="docutils literal"><span class="pre">Derived&amp;</span> <span class="pre">operator-=(difference_type</span> <span class="pre">n);</span></tt></p>
631<table class="docutils field-list" frame="void" rules="none">
632<col class="field-name" />
633<col class="field-body" />
634<tbody valign="top">
635<tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
636static_cast&lt;Derived*&gt;(this)-&gt;advance(-n);
637return *static_cast&lt;Derived*&gt;(this);
638</pre>
639</td>
640</tr>
641</tbody>
642</table>
643<p><tt class="docutils literal"><span class="pre">Derived</span> <span class="pre">operator-(difference_type</span> <span class="pre">n)</span> <span class="pre">const;</span></tt></p>
644<table class="docutils field-list" frame="void" rules="none">
645<col class="field-name" />
646<col class="field-body" />
647<tbody valign="top">
648<tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
649Derived tmp(static_cast&lt;Derived const*&gt;(this));
650return tmp -= n;
651</pre>
652</td>
653</tr>
654</tbody>
655</table>
656<pre class="literal-block">
657template &lt;class Dr, class V, class TC, class R, class D&gt;
658Derived operator+ (iterator_facade&lt;Dr,V,TC,R,D&gt; const&amp;,
659                   typename Derived::difference_type n);
660
661template &lt;class Dr, class V, class TC, class R, class D&gt;
662Derived operator+ (typename Derived::difference_type n,
663                   iterator_facade&lt;Dr,V,TC,R,D&gt; const&amp;);
664</pre>
665<table class="docutils field-list" frame="void" rules="none">
666<col class="field-name" />
667<col class="field-body" />
668<tbody valign="top">
669<tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
670Derived tmp(static_cast&lt;Derived const*&gt;(this));
671return tmp += n;
672</pre>
673</td>
674</tr>
675</tbody>
676</table>
677<pre class="literal-block">
678template &lt;class Dr1, class V1, class TC1, class R1, class D1,
679          class Dr2, class V2, class TC2, class R2, class D2&gt;
680typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
681operator ==(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
682            iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
683</pre>
684<table class="docutils field-list" frame="void" rules="none">
685<col class="field-name" />
686<col class="field-body" />
687<tbody valign="top">
688<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
689<dl class="last docutils">
690<dt>then</dt>
691<dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr1</span> <span class="pre">const&amp;)lhs).equal((Dr2</span> <span class="pre">const&amp;)rhs)</span></tt>.</p>
692</dd>
693<dt>Otherwise,</dt>
694<dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr2</span> <span class="pre">const&amp;)rhs).equal((Dr1</span> <span class="pre">const&amp;)lhs)</span></tt>.</p>
695</dd>
696</dl>
697</td>
698</tr>
699</tbody>
700</table>
701<pre class="literal-block">
702template &lt;class Dr1, class V1, class TC1, class R1, class D1,
703          class Dr2, class V2, class TC2, class R2, class D2&gt;
704typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
705operator !=(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
706            iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
707</pre>
708<table class="docutils field-list" frame="void" rules="none">
709<col class="field-name" />
710<col class="field-body" />
711<tbody valign="top">
712<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
713<dl class="last docutils">
714<dt>then</dt>
715<dd><p class="first last"><tt class="docutils literal"><span class="pre">!((Dr1</span> <span class="pre">const&amp;)lhs).equal((Dr2</span> <span class="pre">const&amp;)rhs)</span></tt>.</p>
716</dd>
717<dt>Otherwise,</dt>
718<dd><p class="first last"><tt class="docutils literal"><span class="pre">!((Dr2</span> <span class="pre">const&amp;)rhs).equal((Dr1</span> <span class="pre">const&amp;)lhs)</span></tt>.</p>
719</dd>
720</dl>
721</td>
722</tr>
723</tbody>
724</table>
725<pre class="literal-block">
726template &lt;class Dr1, class V1, class TC1, class R1, class D1,
727          class Dr2, class V2, class TC2, class R2, class D2&gt;
728typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
729operator &lt;(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
730           iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
731</pre>
732<table class="docutils field-list" frame="void" rules="none">
733<col class="field-name" />
734<col class="field-body" />
735<tbody valign="top">
736<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
737<dl class="last docutils">
738<dt>then</dt>
739<dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr1</span> <span class="pre">const&amp;)lhs).distance_to((Dr2</span> <span class="pre">const&amp;)rhs)</span> <span class="pre">&lt;</span> <span class="pre">0</span></tt>.</p>
740</dd>
741<dt>Otherwise,</dt>
742<dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr2</span> <span class="pre">const&amp;)rhs).distance_to((Dr1</span> <span class="pre">const&amp;)lhs)</span> <span class="pre">&gt;</span> <span class="pre">0</span></tt>.</p>
743</dd>
744</dl>
745</td>
746</tr>
747</tbody>
748</table>
749<pre class="literal-block">
750template &lt;class Dr1, class V1, class TC1, class R1, class D1,
751          class Dr2, class V2, class TC2, class R2, class D2&gt;
752typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
753operator &lt;=(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
754            iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
755</pre>
756<table class="docutils field-list" frame="void" rules="none">
757<col class="field-name" />
758<col class="field-body" />
759<tbody valign="top">
760<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
761<dl class="last docutils">
762<dt>then</dt>
763<dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr1</span> <span class="pre">const&amp;)lhs).distance_to((Dr2</span> <span class="pre">const&amp;)rhs)</span> <span class="pre">&lt;=</span> <span class="pre">0</span></tt>.</p>
764</dd>
765<dt>Otherwise,</dt>
766<dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr2</span> <span class="pre">const&amp;)rhs).distance_to((Dr1</span> <span class="pre">const&amp;)lhs)</span> <span class="pre">&gt;=</span> <span class="pre">0</span></tt>.</p>
767</dd>
768</dl>
769</td>
770</tr>
771</tbody>
772</table>
773<pre class="literal-block">
774template &lt;class Dr1, class V1, class TC1, class R1, class D1,
775          class Dr2, class V2, class TC2, class R2, class D2&gt;
776typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
777operator &gt;(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
778           iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
779</pre>
780<table class="docutils field-list" frame="void" rules="none">
781<col class="field-name" />
782<col class="field-body" />
783<tbody valign="top">
784<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
785<dl class="last docutils">
786<dt>then</dt>
787<dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr1</span> <span class="pre">const&amp;)lhs).distance_to((Dr2</span> <span class="pre">const&amp;)rhs)</span> <span class="pre">&gt;</span> <span class="pre">0</span></tt>.</p>
788</dd>
789<dt>Otherwise,</dt>
790<dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr2</span> <span class="pre">const&amp;)rhs).distance_to((Dr1</span> <span class="pre">const&amp;)lhs)</span> <span class="pre">&lt;</span> <span class="pre">0</span></tt>.</p>
791</dd>
792</dl>
793</td>
794</tr>
795</tbody>
796</table>
797<pre class="literal-block">
798template &lt;class Dr1, class V1, class TC1, class R1, class D1,
799          class Dr2, class V2, class TC2, class R2, class D2&gt;
800typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
801operator &gt;=(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
802            iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
803</pre>
804<table class="docutils field-list" frame="void" rules="none">
805<col class="field-name" />
806<col class="field-body" />
807<tbody valign="top">
808<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
809<dl class="last docutils">
810<dt>then</dt>
811<dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr1</span> <span class="pre">const&amp;)lhs).distance_to((Dr2</span> <span class="pre">const&amp;)rhs)</span> <span class="pre">&gt;=</span> <span class="pre">0</span></tt>.</p>
812</dd>
813<dt>Otherwise,</dt>
814<dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr2</span> <span class="pre">const&amp;)rhs).distance_to((Dr1</span> <span class="pre">const&amp;)lhs)</span> <span class="pre">&lt;=</span> <span class="pre">0</span></tt>.</p>
815</dd>
816</dl>
817</td>
818</tr>
819</tbody>
820</table>
821<pre class="literal-block" id="minus">
822template &lt;class Dr1, class V1, class TC1, class R1, class D1,
823          class Dr2, class V2, class TC2, class R2, class D2&gt;
824typename enable_if_interoperable&lt;Dr1,Dr2,difference&gt;::type
825operator -(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
826           iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
827</pre>
828<table class="docutils field-list" frame="void" rules="none">
829<col class="field-name" />
830<col class="field-body" />
831<tbody valign="top">
832<tr class="field"><th class="field-name">Return Type:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
833<blockquote>
834<dl class="docutils">
835<dt>then</dt>
836<dd><p class="first last"><tt class="docutils literal"><span class="pre">difference</span></tt> shall be
837<tt class="docutils literal"><span class="pre">iterator_traits&lt;Dr1&gt;::difference_type</span></tt>.</p>
838</dd>
839<dt>Otherwise</dt>
840<dd><p class="first last"><tt class="docutils literal"><span class="pre">difference</span></tt> shall be <tt class="docutils literal"><span class="pre">iterator_traits&lt;Dr2&gt;::difference_type</span></tt></p>
841</dd>
842</dl>
843</blockquote>
844</td>
845</tr>
846<tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
847<dl class="last docutils">
848<dt>then</dt>
849<dd><p class="first last"><tt class="docutils literal"><span class="pre">-((Dr1</span> <span class="pre">const&amp;)lhs).distance_to((Dr2</span> <span class="pre">const&amp;)rhs)</span></tt>.</p>
850</dd>
851<dt>Otherwise,</dt>
852<dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr2</span> <span class="pre">const&amp;)rhs).distance_to((Dr1</span> <span class="pre">const&amp;)lhs)</span></tt>.</p>
853</dd>
854</dl>
855</td>
856</tr>
857</tbody>
858</table>
859</div>
860</div>
861<div class="section" id="tutorial-example">
862<h1><a class="toc-backref" href="#id31">Tutorial Example</a></h1>
863<!-- Copyright David Abrahams 2004. Use, modification and distribution is -->
864<!-- subject to the Boost Software License, Version 1.0. (See accompanying -->
865<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
866<p>In this section we'll walk through the implementation of a few
867iterators using <tt class="docutils literal"><span class="pre">iterator_facade</span></tt>, based around the simple
868example of a linked list of polymorphic objects.  This example was
869inspired by a <a class="reference external" href="http://thread.gmane.org/gmane.comp.lib.boost.user/5100">posting</a> by Keith Macdonald on the <a class="reference external" href="http://www.boost.org/more/mailing_lis…

Large files files are truncated, but you can click here to view the full file