updated to match the rst file

[SVN r20150]
This commit is contained in:
Jeremy Siek
2003-09-22 13:58:20 +00:00
parent 50ab635593
commit f6cbffeda0

View File

@ -7,7 +7,7 @@
<title>New Iterator Concepts</title> <title>New Iterator Concepts</title>
<meta name="author" content="David Abrahams, Jeremy Siek, Thomas Witt" /> <meta name="author" content="David Abrahams, Jeremy Siek, Thomas Witt" />
<meta name="organization" content="Boost Consulting, Indiana University Open Systems Lab, University of Hanover Institute for Transport Railway Operation and Construction" /> <meta name="organization" content="Boost Consulting, Indiana University Open Systems Lab, University of Hanover Institute for Transport Railway Operation and Construction" />
<meta name="date" content="2003-09-20" /> <meta name="date" content="2003-09-22" />
<meta name="copyright" content="Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved" /> <meta name="copyright" content="Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved" />
<link rel="stylesheet" href="default.css" type="text/css" /> <link rel="stylesheet" href="default.css" type="text/css" />
</head> </head>
@ -25,7 +25,7 @@
<tr><th class="docinfo-name">Organization:</th> <tr><th class="docinfo-name">Organization:</th>
<td><a class="first reference" href="http://www.boost-consulting.com">Boost Consulting</a>, Indiana University <a class="reference" href="http://www.osl.iu.edu">Open Systems Lab</a>, University of Hanover <a class="last reference" href="http://www.ive.uni-hannover.de">Institute for Transport Railway Operation and Construction</a></td></tr> <td><a class="first reference" href="http://www.boost-consulting.com">Boost Consulting</a>, Indiana University <a class="reference" href="http://www.osl.iu.edu">Open Systems Lab</a>, University of Hanover <a class="last reference" href="http://www.ive.uni-hannover.de">Institute for Transport Railway Operation and Construction</a></td></tr>
<tr><th class="docinfo-name">Date:</th> <tr><th class="docinfo-name">Date:</th>
<td>2003-09-20</td></tr> <td>2003-09-22</td></tr>
<tr class="field"><th class="docinfo-name">Number:</th><td class="field-body"><strong>This document is a revised version of the official</strong> N1477=03-0060</td> <tr class="field"><th class="docinfo-name">Number:</th><td class="field-body"><strong>This document is a revised version of the official</strong> N1477=03-0060</td>
</tr> </tr>
<tr><th class="docinfo-name">Copyright:</th> <tr><th class="docinfo-name">Copyright:</th>
@ -57,22 +57,21 @@ is a revision of paper <a class="reference" href="http://anubis.dkuug.dk/jtc1/sc
<li><a class="reference" href="#readable-iterators-lib-readable-iterators" id="id7" name="id7">Readable Iterators [lib.readable.iterators]</a></li> <li><a class="reference" href="#readable-iterators-lib-readable-iterators" id="id7" name="id7">Readable Iterators [lib.readable.iterators]</a></li>
<li><a class="reference" href="#writable-iterators-lib-writable-iterators" id="id8" name="id8">Writable Iterators [lib.writable.iterators]</a></li> <li><a class="reference" href="#writable-iterators-lib-writable-iterators" id="id8" name="id8">Writable Iterators [lib.writable.iterators]</a></li>
<li><a class="reference" href="#swappable-iterators-lib-swappable-iterators" id="id9" name="id9">Swappable Iterators [lib.swappable.iterators]</a></li> <li><a class="reference" href="#swappable-iterators-lib-swappable-iterators" id="id9" name="id9">Swappable Iterators [lib.swappable.iterators]</a></li>
<li><a class="reference" href="#readable-lvalue-iterators-lib-readable-lvalue-iterators" id="id10" name="id10">Readable Lvalue Iterators [lib.readable.lvalue.iterators]</a></li> <li><a class="reference" href="#lvalue-iterators-lib-lvalue-iterators" id="id10" name="id10">Lvalue Iterators [lib.lvalue.iterators]</a></li>
<li><a class="reference" href="#writable-lvalue-iterators-lib-writable-lvalue-iterators" id="id11" name="id11">Writable Lvalue Iterators [lib.writable.lvalue.iterators]</a></li>
</ul> </ul>
</li> </li>
<li><a class="reference" href="#iterator-traversal-concepts-lib-iterator-traversal" id="id12" name="id12">Iterator Traversal Concepts [lib.iterator.traversal]</a><ul> <li><a class="reference" href="#iterator-traversal-concepts-lib-iterator-traversal" id="id11" name="id11">Iterator Traversal Concepts [lib.iterator.traversal]</a><ul>
<li><a class="reference" href="#incrementable-iterators-lib-incrementable-iterators" id="id13" name="id13">Incrementable Iterators [lib.incrementable.iterators]</a></li> <li><a class="reference" href="#incrementable-iterators-lib-incrementable-iterators" id="id12" name="id12">Incrementable Iterators [lib.incrementable.iterators]</a></li>
<li><a class="reference" href="#single-pass-iterators-lib-single-pass-iterators" id="id14" name="id14">Single Pass Iterators [lib.single.pass.iterators]</a></li> <li><a class="reference" href="#single-pass-iterators-lib-single-pass-iterators" id="id13" name="id13">Single Pass Iterators [lib.single.pass.iterators]</a></li>
<li><a class="reference" href="#forward-traversal-iterators-lib-forward-traversal-iterators" id="id15" name="id15">Forward Traversal Iterators [lib.forward.traversal.iterators]</a></li> <li><a class="reference" href="#forward-traversal-iterators-lib-forward-traversal-iterators" id="id14" name="id14">Forward Traversal Iterators [lib.forward.traversal.iterators]</a></li>
<li><a class="reference" href="#bidirectional-traversal-iterators-lib-bidirectional-traversal-iterators" id="id16" name="id16">Bidirectional Traversal Iterators [lib.bidirectional.traversal.iterators]</a></li> <li><a class="reference" href="#bidirectional-traversal-iterators-lib-bidirectional-traversal-iterators" id="id15" name="id15">Bidirectional Traversal Iterators [lib.bidirectional.traversal.iterators]</a></li>
<li><a class="reference" href="#random-access-traversal-iterators-lib-random-access-traversal-iterators" id="id17" name="id17">Random Access Traversal Iterators [lib.random.access.traversal.iterators]</a></li> <li><a class="reference" href="#random-access-traversal-iterators-lib-random-access-traversal-iterators" id="id16" name="id16">Random Access Traversal Iterators [lib.random.access.traversal.iterators]</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
</li> </li>
<li><a class="reference" href="#addition-to-lib-iterator-synopsis" id="id18" name="id18">Addition to [lib.iterator.synopsis]</a></li> <li><a class="reference" href="#addition-to-lib-iterator-synopsis" id="id17" name="id17">Addition to [lib.iterator.synopsis]</a></li>
<li><a class="reference" href="#addition-to-lib-iterator-traits" id="id19" name="id19">Addition to [lib.iterator.traits]</a></li> <li><a class="reference" href="#addition-to-lib-iterator-traits" id="id18" name="id18">Addition to [lib.iterator.traits]</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
@ -236,12 +235,8 @@ set of concepts handles the syntax and semantics of value access:</p>
<li>Readable Iterator</li> <li>Readable Iterator</li>
<li>Writable Iterator</li> <li>Writable Iterator</li>
<li>Swappable Iterator</li> <li>Swappable Iterator</li>
<li>Readable Lvalue Iterator</li> <li>Lvalue Iterator</li>
<li>Writable Lvalue Iterator</li>
</ul> </ul>
<p>The refinement relationships among these iterator concepts are given
in the following diagram.</p>
<p><img alt="access.png" src="access.png" /></p>
<p>The access concepts describe requirements related to <tt class="literal"><span class="pre">operator*</span></tt> and <p>The access concepts describe requirements related to <tt class="literal"><span class="pre">operator*</span></tt> and
<tt class="literal"><span class="pre">operator-&gt;</span></tt>, including the <tt class="literal"><span class="pre">value_type</span></tt>, <tt class="literal"><span class="pre">reference</span></tt>, and <tt class="literal"><span class="pre">operator-&gt;</span></tt>, including the <tt class="literal"><span class="pre">value_type</span></tt>, <tt class="literal"><span class="pre">reference</span></tt>, and
<tt class="literal"><span class="pre">pointer</span></tt> associated types.</p> <tt class="literal"><span class="pre">pointer</span></tt> associated types.</p>
@ -269,17 +264,17 @@ given in the following diagram.</p>
dispatching. There are two hierarchies of tags, one for the access dispatching. There are two hierarchies of tags, one for the access
concepts and one for the traversal concepts. The tags are related via concepts and one for the traversal concepts. The tags are related via
inheritance so that a tag is convertible to another tag if the concept inheritance so that a tag is convertible to another tag if the concept
associated with the first tag is a refinement of the second tag. We associated with the first tag is a refinement of the second tag.
use virtual inheritance of the diamonds in the current hierarchy, and There is not a tag for Lvalue Iterator because one can easily deduce
because of possible diamonds that could be created when programmers whether an iterator is an Lvalue Iterator by checking whether
define new iterator concepts and the corresponding tags.</p> <tt class="literal"><span class="pre">iterator_traits&lt;Iterator&gt;::reference</span></tt> is a real reference.</p>
<p>We provide an access mechanism for mapping iterator types to the new <p>We provide an access mechanism for mapping iterator types to the new
tags. Our design reuses <tt class="literal"><span class="pre">iterator_traits&lt;Iter&gt;::iterator_category</span></tt> tags. Our design reuses <tt class="literal"><span class="pre">iterator_traits&lt;Iter&gt;::iterator_category</span></tt>
as the access mechanism. To enable this, a pair of access and as the access mechanism. To enable this, a pair of access and
traversal tags are combined into a single type using the following traversal tags are combined into a single type using the following
<cite>iterator_tag</cite> class.</p> <cite>iterator_tag</cite> class.</p>
<pre class="literal-block"> <pre class="literal-block">
template &lt;class AccessTag, class TraversalTag&gt; template &lt;class AccessTag, class Reference, class TraversalTag&gt;
struct iterator_tag : /* appropriate old category or categories */ struct iterator_tag : /* appropriate old category or categories */
{ {
typedef AccessTag access; typedef AccessTag access;
@ -357,9 +352,8 @@ member of type <tt class="literal"><span class="pre">T</span></tt>.</p>
<tt class="literal"><span class="pre">iterator_traits&lt;X&gt;::value_type</span></tt></td> <tt class="literal"><span class="pre">iterator_traits&lt;X&gt;::value_type</span></tt></td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<tr><td><tt class="literal"><span class="pre">access_category&lt;X&gt;::type</span></tt></td> <tr><td><tt class="literal"><span class="pre">is_readable&lt;X&gt;::type</span></tt></td>
<td>Convertible to <td><tt class="literal"><span class="pre">truetype</span></tt></td>
<tt class="literal"><span class="pre">readable_iterator_tag</span></tt></td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<tr><td><tt class="literal"><span class="pre">*a</span></tt></td> <tr><td><tt class="literal"><span class="pre">*a</span></tt></td>
@ -399,9 +393,8 @@ output.</p>
</tr> </tr>
</thead> </thead>
<tbody valign="top"> <tbody valign="top">
<tr><td><tt class="literal"><span class="pre">access_category&lt;X&gt;::type</span></tt></td> <tr><td><tt class="literal"><span class="pre">is_writable&lt;X&gt;::type</span></tt></td>
<td>Convertible to <td><tt class="literal"><span class="pre">true_type</span></tt></td>
<tt class="literal"><span class="pre">writable_iterator_tag</span></tt></td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<tr><td><tt class="literal"><span class="pre">*a</span> <span class="pre">=</span> <span class="pre">o</span></tt></td> <tr><td><tt class="literal"><span class="pre">*a</span> <span class="pre">=</span> <span class="pre">o</span></tt></td>
@ -435,6 +428,10 @@ semantics.</p>
</tr> </tr>
</thead> </thead>
<tbody valign="top"> <tbody valign="top">
<tr><td><tt class="literal"><span class="pre">is_swappable&lt;X&gt;::type</span></tt></td>
<td><tt class="literal"><span class="pre">true_type</span></tt></td>
<td>&nbsp;</td>
</tr>
<tr><td><tt class="literal"><span class="pre">iter_swap(a,</span> <span class="pre">b)</span></tt></td> <tr><td><tt class="literal"><span class="pre">iter_swap(a,</span> <span class="pre">b)</span></tt></td>
<td><tt class="literal"><span class="pre">void</span></tt></td> <td><tt class="literal"><span class="pre">void</span></tt></td>
<td>post: the pointed to values are exchanged</td> <td>post: the pointed to values are exchanged</td>
@ -447,9 +444,9 @@ semantics.</p>
<dd>is also a model of <em>Swappable Iterator</em>. <em>--end note</em>]</dd> <dd>is also a model of <em>Swappable Iterator</em>. <em>--end note</em>]</dd>
</dl> </dl>
</div> </div>
<div class="section" id="readable-lvalue-iterators-lib-readable-lvalue-iterators"> <div class="section" id="lvalue-iterators-lib-lvalue-iterators">
<h4><a class="toc-backref" href="#id10" name="readable-lvalue-iterators-lib-readable-lvalue-iterators">Readable Lvalue Iterators [lib.readable.lvalue.iterators]</a></h4> <h4><a class="toc-backref" href="#id10" name="lvalue-iterators-lib-lvalue-iterators">Lvalue Iterators [lib.lvalue.iterators]</a></h4>
<p>The <em>Readable Lvalue Iterator</em> concept adds the requirement that the <p>The <em>Lvalue Iterator</em> concept adds the requirement that the
<tt class="literal"><span class="pre">reference</span></tt> type be a reference to the value type of the iterator.</p> <tt class="literal"><span class="pre">reference</span></tt> type be a reference to the value type of the iterator.</p>
<blockquote> <blockquote>
<table border class="table"> <table border class="table">
@ -459,7 +456,7 @@ semantics.</p>
<col width="34%" /> <col width="34%" />
</colgroup> </colgroup>
<thead valign="bottom"> <thead valign="bottom">
<tr><th colspan="3">Readable Lvalue Iterator Requirements (in addition to Readable Iterator)</th> <tr><th colspan="3">Lvalue Iterator Requirements</th>
</tr> </tr>
<tr><th>Expression</th> <tr><th>Expression</th>
<th>Return Type</th> <th>Return Type</th>
@ -474,53 +471,19 @@ semantics.</p>
where <em>cv</em> is an optional where <em>cv</em> is an optional
cv-qualification</td> cv-qualification</td>
</tr> </tr>
<tr><td><tt class="literal"><span class="pre">access_category&lt;X&gt;::type</span></tt></td>
<td>Convertible to
<tt class="literal"><span class="pre">readable_lvalue_iterator_tag</span></tt></td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<div class="section" id="writable-lvalue-iterators-lib-writable-lvalue-iterators">
<h4><a class="toc-backref" href="#id11" name="writable-lvalue-iterators-lib-writable-lvalue-iterators">Writable Lvalue Iterators [lib.writable.lvalue.iterators]</a></h4>
<p>The <em>Writable Lvalue Iterator</em> concept adds the requirement that the
<tt class="literal"><span class="pre">reference</span></tt> type be a non-const reference to the value type of the
iterator.</p>
<blockquote>
<table border class="table">
<colgroup>
<col width="45%" />
<col width="55%" />
</colgroup>
<thead valign="bottom">
<tr><th colspan="2">Writable Lvalue Iterator Requirements (in addition to Readable Lvalue Iterator)</th>
</tr>
<tr><th>Expression</th>
<th>Return Type</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><tt class="literal"><span class="pre">iterator_traits&lt;X&gt;::reference</span></tt></td>
<td><tt class="literal"><span class="pre">iterator_traits&lt;X&gt;::value_type&amp;</span></tt></td>
</tr>
<tr><td><tt class="literal"><span class="pre">access_category&lt;X&gt;::type</span></tt></td>
<td>Convertible to <tt class="literal"><span class="pre">writable_lvalue_iterator_tag</span></tt></td>
</tr>
</tbody> </tbody>
</table> </table>
</blockquote> </blockquote>
</div> </div>
</div> </div>
<div class="section" id="iterator-traversal-concepts-lib-iterator-traversal"> <div class="section" id="iterator-traversal-concepts-lib-iterator-traversal">
<h3><a class="toc-backref" href="#id12" name="iterator-traversal-concepts-lib-iterator-traversal">Iterator Traversal Concepts [lib.iterator.traversal]</a></h3> <h3><a class="toc-backref" href="#id11" name="iterator-traversal-concepts-lib-iterator-traversal">Iterator Traversal Concepts [lib.iterator.traversal]</a></h3>
<p>In the tables below, <tt class="literal"><span class="pre">X</span></tt> is an iterator type, <tt class="literal"><span class="pre">a</span></tt> and <tt class="literal"><span class="pre">b</span></tt> are <p>In the tables below, <tt class="literal"><span class="pre">X</span></tt> is an iterator type, <tt class="literal"><span class="pre">a</span></tt> and <tt class="literal"><span class="pre">b</span></tt> are
constant objects of type <tt class="literal"><span class="pre">X</span></tt>, <tt class="literal"><span class="pre">r</span></tt> and <tt class="literal"><span class="pre">s</span></tt> are mutable objects of constant objects of type <tt class="literal"><span class="pre">X</span></tt>, <tt class="literal"><span class="pre">r</span></tt> and <tt class="literal"><span class="pre">s</span></tt> are mutable objects of
type <tt class="literal"><span class="pre">X</span></tt>, <tt class="literal"><span class="pre">T</span></tt> is <tt class="literal"><span class="pre">std::iterator_traits&lt;X&gt;::value_type</span></tt>, and type <tt class="literal"><span class="pre">X</span></tt>, <tt class="literal"><span class="pre">T</span></tt> is <tt class="literal"><span class="pre">std::iterator_traits&lt;X&gt;::value_type</span></tt>, and
<tt class="literal"><span class="pre">v</span></tt> is a constant object of type <tt class="literal"><span class="pre">T</span></tt>.</p> <tt class="literal"><span class="pre">v</span></tt> is a constant object of type <tt class="literal"><span class="pre">T</span></tt>.</p>
<div class="section" id="incrementable-iterators-lib-incrementable-iterators"> <div class="section" id="incrementable-iterators-lib-incrementable-iterators">
<h4><a class="toc-backref" href="#id13" name="incrementable-iterators-lib-incrementable-iterators">Incrementable Iterators [lib.incrementable.iterators]</a></h4> <h4><a class="toc-backref" href="#id12" name="incrementable-iterators-lib-incrementable-iterators">Incrementable Iterators [lib.incrementable.iterators]</a></h4>
<p>A class or built-in type <tt class="literal"><span class="pre">X</span></tt> models the <em>Incrementable Iterator</em> <p>A class or built-in type <tt class="literal"><span class="pre">X</span></tt> models the <em>Incrementable Iterator</em>
concept if the following expressions are valid and respect the stated concept if the following expressions are valid and respect the stated
semantics.</p> semantics.</p>
@ -557,7 +520,7 @@ semantics.</p>
</blockquote> </blockquote>
</div> </div>
<div class="section" id="single-pass-iterators-lib-single-pass-iterators"> <div class="section" id="single-pass-iterators-lib-single-pass-iterators">
<h4><a class="toc-backref" href="#id14" name="single-pass-iterators-lib-single-pass-iterators">Single Pass Iterators [lib.single.pass.iterators]</a></h4> <h4><a class="toc-backref" href="#id13" name="single-pass-iterators-lib-single-pass-iterators">Single Pass Iterators [lib.single.pass.iterators]</a></h4>
<p>A class or built-in type <tt class="literal"><span class="pre">X</span></tt> models the <em>Single Pass Iterator</em> <p>A class or built-in type <tt class="literal"><span class="pre">X</span></tt> models the <em>Single Pass Iterator</em>
concept if the following expressions are valid and respect the stated concept if the following expressions are valid and respect the stated
semantics.</p> semantics.</p>
@ -602,7 +565,7 @@ its domain</td>
</blockquote> </blockquote>
</div> </div>
<div class="section" id="forward-traversal-iterators-lib-forward-traversal-iterators"> <div class="section" id="forward-traversal-iterators-lib-forward-traversal-iterators">
<h4><a class="toc-backref" href="#id15" name="forward-traversal-iterators-lib-forward-traversal-iterators">Forward Traversal Iterators [lib.forward.traversal.iterators]</a></h4> <h4><a class="toc-backref" href="#id14" name="forward-traversal-iterators-lib-forward-traversal-iterators">Forward Traversal Iterators [lib.forward.traversal.iterators]</a></h4>
<p>A class or built-in type <tt class="literal"><span class="pre">X</span></tt> models the <em>Forward Traversal Iterator</em> <p>A class or built-in type <tt class="literal"><span class="pre">X</span></tt> models the <em>Forward Traversal Iterator</em>
concept if the following expressions are valid and respect the stated concept if the following expressions are valid and respect the stated
semantics.</p> semantics.</p>
@ -648,7 +611,7 @@ the distance between iterators</td>
</blockquote> </blockquote>
</div> </div>
<div class="section" id="bidirectional-traversal-iterators-lib-bidirectional-traversal-iterators"> <div class="section" id="bidirectional-traversal-iterators-lib-bidirectional-traversal-iterators">
<h4><a class="toc-backref" href="#id16" name="bidirectional-traversal-iterators-lib-bidirectional-traversal-iterators">Bidirectional Traversal Iterators [lib.bidirectional.traversal.iterators]</a></h4> <h4><a class="toc-backref" href="#id15" name="bidirectional-traversal-iterators-lib-bidirectional-traversal-iterators">Bidirectional Traversal Iterators [lib.bidirectional.traversal.iterators]</a></h4>
<p>A class or built-in type <tt class="literal"><span class="pre">X</span></tt> models the <em>Bidirectional Traversal <p>A class or built-in type <tt class="literal"><span class="pre">X</span></tt> models the <em>Bidirectional Traversal
Iterator</em> concept if the following expressions are valid and respect Iterator</em> concept if the following expressions are valid and respect
the stated semantics.</p> the stated semantics.</p>
@ -690,7 +653,7 @@ dereferenceable. <tt class="literal"><span class="pre">--(++r)</span> <span clas
</blockquote> </blockquote>
</div> </div>
<div class="section" id="random-access-traversal-iterators-lib-random-access-traversal-iterators"> <div class="section" id="random-access-traversal-iterators-lib-random-access-traversal-iterators">
<h4><a class="toc-backref" href="#id17" name="random-access-traversal-iterators-lib-random-access-traversal-iterators">Random Access Traversal Iterators [lib.random.access.traversal.iterators]</a></h4> <h4><a class="toc-backref" href="#id16" name="random-access-traversal-iterators-lib-random-access-traversal-iterators">Random Access Traversal Iterators [lib.random.access.traversal.iterators]</a></h4>
<p>A class or built-in type <tt class="literal"><span class="pre">X</span></tt> models the <em>Random Access Traversal <p>A class or built-in type <tt class="literal"><span class="pre">X</span></tt> models the <em>Random Access Traversal
Iterator</em> concept if the following expressions are valid and respect Iterator</em> concept if the following expressions are valid and respect
the stated semantics. In the table below, <tt class="literal"><span class="pre">Distance</span></tt> is the stated semantics. In the table below, <tt class="literal"><span class="pre">Distance</span></tt> is
@ -805,31 +768,23 @@ relation</td>
</div> </div>
</div> </div>
<div class="section" id="addition-to-lib-iterator-synopsis"> <div class="section" id="addition-to-lib-iterator-synopsis">
<h2><a class="toc-backref" href="#id18" name="addition-to-lib-iterator-synopsis">Addition to [lib.iterator.synopsis]</a></h2> <h2><a class="toc-backref" href="#id17" name="addition-to-lib-iterator-synopsis">Addition to [lib.iterator.synopsis]</a></h2>
<pre class="literal-block"> <pre class="literal-block">
// lib.iterator.traits, traits and tags // lib.iterator.traits, traits and tags
template &lt;class Iterator&gt; struct access_category; template &lt;class Iterator&gt; struct is_readable;
template &lt;class Iterator&gt; struct is_writable;
template &lt;class Iterator&gt; struct is_swappable;
template &lt;class Iterator&gt; struct traversal_category; template &lt;class Iterator&gt; struct traversal_category;
template &lt;class AccessTag, class TraversalTag&gt; enum iterator_access { readable_iterator = 1, writable_iterator = 2,
swappable_iterator = 4, lvalue_iterator = 8 };
template &lt;iterator_access x, class TraversalTag&gt;
struct iterator_tag : /* appropriate old category or categories */ { struct iterator_tag : /* appropriate old category or categories */ {
typedef AccessTag access; static const iterator_access access = x;
typedef TraversalTag traversal; typedef TraversalTag traversal;
}; };
struct readable_iterator_tag { };
struct writable_iterator_tag { };
struct swappable_iterator_tag { };
struct readable_writable_iterator_tag
: virtual readable_iterator_tag
, virtual writable_iterator_tag
, virtual swappable_iterator_tag { };
struct readable_lvalue_iterator_tag
: virtual readable_iterator_tag { };
struct writable_lvalue_iterator_tag
: virtual public readable_writable_iterator_tag
, virtual public readable_lvalue_iterator_tag { };
struct incrementable_iterator_tag { }; struct incrementable_iterator_tag { };
struct single_pass_iterator_tag : incrementable_iterator_tag { }; struct single_pass_iterator_tag : incrementable_iterator_tag { };
struct forward_traversal_tag : single_pass_iterator_tag { }; struct forward_traversal_tag : single_pass_iterator_tag { };
@ -841,15 +796,15 @@ struct input_output_iterator_tag : input_iterator_tag, output_iterator_tag {};
</pre> </pre>
</div> </div>
<div class="section" id="addition-to-lib-iterator-traits"> <div class="section" id="addition-to-lib-iterator-traits">
<h2><a class="toc-backref" href="#id19" name="addition-to-lib-iterator-traits">Addition to [lib.iterator.traits]</a></h2> <h2><a class="toc-backref" href="#id18" name="addition-to-lib-iterator-traits">Addition to [lib.iterator.traits]</a></h2>
<p>The <tt class="literal"><span class="pre">iterator_tag</span></tt> class template is an iterator category tag that <p>The <tt class="literal"><span class="pre">iterator_tag</span></tt> class template is an iterator category tag that
encodes the access and traversal tags in addition to being compatible encodes the access enum and traversal tag in addition to being compatible
with the original iterator tags. The <tt class="literal"><span class="pre">iterator_tag</span></tt> class inherits with the original iterator tags. The <tt class="literal"><span class="pre">iterator_tag</span></tt> class inherits
from one of the original iterator tags according to the following from one of the original iterator tags according to the following
pseudo-code.</p> pseudo-code.</p>
<pre class="literal-block"> <pre class="literal-block">
inherit-category(access-tag, traversal-tag) = inherit-category(access, traversal-tag) =
if (access-tag is convertible to readable_lvalue_iterator_tag) { if (access &amp; lvalue_iterator) {
if (traversal-tag is convertible to random_access_traversal_tag) if (traversal-tag is convertible to random_access_traversal_tag)
return random_access_iterator_tag; return random_access_iterator_tag;
else if (traversal-tag is convertible to bidirectional_traversal_tag) else if (traversal-tag is convertible to bidirectional_traversal_tag)
@ -861,52 +816,64 @@ inherit-category(access-tag, traversal-tag) =
return input_output_iterator_tag; return input_output_iterator_tag;
else else
return input_iterator_tag; return input_iterator_tag;
else if (access-tag is convertible to writable_iterator_tag) else if (access &amp; writable_iterator)
return output_iterator_tag; return output_iterator_tag;
else else
return null_category_tag; return null_category_tag;
} else if (access-tag is convertible to readable_writable_iterator_tag } else if ((access &amp; readable_iterator) and (access &amp; writable_iterator)
and traversal-tag is convertible to single_pass_iterator_tag) and traversal-tag is convertible to single_pass_iterator_tag)
return input_output_iterator_tag; return input_output_iterator_tag;
else if (access-tag is convertible to readable_iterator_tag else if (access &amp; readable_iterator
and traversal-tag is convertible to single_pass_iterator_tag) and traversal-tag is convertible to single_pass_iterator_tag)
return input_iterator_tag; return input_iterator_tag;
else if (access-tag is convertible to writable_iterator_tag else if (access &amp; writable_iterator
and traversal-tag is convertible to incrementable_iterator_tag) and traversal-tag is convertible to incrementable_iterator_tag)
return output_iterator_tag; return output_iterator_tag;
else else
return null_category_tag; return null_category_tag;
</pre> </pre>
<p>If the argument for the template parameter <tt class="literal"><span class="pre">AccessTag</span></tt> is not <p>If the argument for <tt class="literal"><span class="pre">TraversalTag</span></tt> is not convertible to
convertible to one or more of: <tt class="literal"><span class="pre">readable_iterator_tag</span></tt>,
<tt class="literal"><span class="pre">writable_iterator_tag</span></tt>, <tt class="literal"><span class="pre">swappable_iterator_tag</span></tt>, or if the
argument for <tt class="literal"><span class="pre">TraversalTag</span></tt> is not convertible to
<tt class="literal"><span class="pre">incrementable_iterator_tag</span></tt> then the programm is ill-formed.</p> <tt class="literal"><span class="pre">incrementable_iterator_tag</span></tt> then the programm is ill-formed.</p>
<p>The <tt class="literal"><span class="pre">access_category</span></tt> and <tt class="literal"><span class="pre">traversal_category</span></tt> class templates are <p>The <tt class="literal"><span class="pre">is_readable</span></tt>, <tt class="literal"><span class="pre">is_writable</span></tt>, <tt class="literal"><span class="pre">is_swappable</span></tt>, and
traits classes. For iterators whose <tt class="literal"><span class="pre">traversal_category</span></tt> class templates are traits classes. For
<tt class="literal"><span class="pre">iterator_traits&lt;Iter&gt;::iterator_category</span></tt> type is <tt class="literal"><span class="pre">iterator_tag</span></tt>, iterators whose <tt class="literal"><span class="pre">iterator_traits&lt;Iter&gt;::iterator_category</span></tt> type is
the <tt class="literal"><span class="pre">access_category</span></tt> and <tt class="literal"><span class="pre">traversal_category</span></tt> traits access the <tt class="literal"><span class="pre">iterator_tag</span></tt>, these traits obtain the <tt class="literal"><span class="pre">access</span></tt> enum and
<tt class="literal"><span class="pre">access</span></tt> and <tt class="literal"><span class="pre">traversal</span></tt> member types within <tt class="literal"><span class="pre">iterator_tag</span></tt>. <tt class="literal"><span class="pre">traversal</span></tt> member type from within <tt class="literal"><span class="pre">iterator_tag</span></tt>. For iterators
For iterators whose <tt class="literal"><span class="pre">iterator_traits&lt;Iter&gt;::iterator_category</span></tt> type whose <tt class="literal"><span class="pre">iterator_traits&lt;Iter&gt;::iterator_category</span></tt> type is not
is not <tt class="literal"><span class="pre">iterator_tag</span></tt> and instead is a tag convertible to one of the <tt class="literal"><span class="pre">iterator_tag</span></tt> and instead is a tag convertible to one of the
original tags, the appropriate traversal and access tags is deduced. original tags, the appropriate traversal tag and access bits are
The following pseudo-code describes the algorithm.</p> deduced. The following pseudo-code describes the algorithm.</p>
<pre class="literal-block"> <pre class="literal-block">
access-category(Iterator) = is-readable(Iterator) =
cat = iterator_traits&lt;Iterator&gt;::iterator_category; cat = iterator_traits&lt;Iterator&gt;::iterator_category;
if (cat == iterator_tag&lt;Access,Traversal&gt;) if (cat == iterator_tag&lt;Access,Traversal&gt;)
return Access; return Access % readable_iterator;
else if (cat is convertible to input_iterator_tag)
return true;
else
return false;
is-writable(Iterator) =
cat = iterator_traits&lt;Iterator&gt;::iterator_category;
if (cat == iterator_tag&lt;Access,Traversal&gt;)
return Access % writable_iterator;
else if (cat is convertible to forward_iterator_tag
or output_iterator_tag)
return true;
else
return false;
is-swappable(Iterator) =
cat = iterator_traits&lt;Iterator&gt;::iterator_category;
if (cat == iterator_tag&lt;Access,Traversal&gt;)
return Access % swappable_iterator;
else if (cat is convertible to forward_iterator_tag) { else if (cat is convertible to forward_iterator_tag) {
if (iterator_traits&lt;Iterator&gt;::reference is a const reference) if (iterator_traits&lt;Iterator&gt;::reference is a const reference)
return readable_lvalue_iterator_tag; return false;
else else
return writable_lvalue_iterator_tag; return true;
} else if (cat is convertible to input_iterator_tag) } else
return readable_iterator_tag; return false;
else if (cat is convertible to output_iterator_tag)
return writable_iterator_tag;
else
return null_category_tag;
traversal-category(Iterator) = traversal-category(Iterator) =
cat = iterator_traits&lt;Iterator&gt;::iterator_category; cat = iterator_traits&lt;Iterator&gt;::iterator_category;
@ -929,15 +896,18 @@ traversal-category(Iterator) =
category tags for pointer types.</p> category tags for pointer types.</p>
<pre class="literal-block"> <pre class="literal-block">
template &lt;typename T&gt; template &lt;typename T&gt;
struct access_category&lt;const T*&gt; struct is_readable&lt;const T*&gt; { typedef true_type type; };
{
typedef readable_lvalue_iterator_tag type;
};
template &lt;typename T&gt; template &lt;typename T&gt;
struct access_category&lt;T*&gt; struct is_writable&lt;const T*&gt; { typedef false_type type; };
{ template &lt;typename T&gt;
typedef writable_lvalue_iterator_tag type; struct is_swappable&lt;const T*&gt; { typedef false_type type; };
};
template &lt;typename T&gt;
struct is_readable&lt;T*&gt; { typedef true_type type; };
template &lt;typename T&gt;
struct is_writable&lt;T*&gt; { typedef true_type type; };
template &lt;typename T&gt;
struct is_swappable&lt;T*&gt; { typedef true_type type; };
template &lt;typename T&gt; template &lt;typename T&gt;
struct traversal_category&lt;T*&gt; struct traversal_category&lt;T*&gt;