resolved some issues with counting_iterator

[SVN r21639]
This commit is contained in:
Jeremy Siek
2004-01-12 19:01:57 +00:00
parent b2407b0191
commit 6085e03da0
6 changed files with 88 additions and 39 deletions

View File

@ -63,6 +63,12 @@ template <
class counting_iterator class counting_iterator
{ {
public: public:
typedef Incrementable value_type;
typedef const Incrementable& reference;
typedef const Incrementable* pointer;
typedef /* see below */ difference_type;
typedef /* see below */ iterator_category;
counting_iterator(); counting_iterator();
counting_iterator(counting_iterator const& rhs); counting_iterator(counting_iterator const& rhs);
explicit counting_iterator(Incrementable x); explicit counting_iterator(Incrementable x);
@ -74,6 +80,12 @@ class counting_iterator
Incrementable m_inc; // exposition Incrementable m_inc; // exposition
}; };
</pre> </pre>
<p>If the <tt class="literal"><span class="pre">Diference</span></tt> argument is <tt class="literal"><span class="pre">use_default</span></tt> then the
<tt class="literal"><span class="pre">difference_type</span></tt> member is an implementation defined signed
integral type.</p>
<p>The member <tt class="literal"><span class="pre">iterator_category</span></tt> is a type that satisfies the
requirements of the concepts modeled by the <tt class="literal"><span class="pre">counting_iterator</span></tt> as
specified in the models section.</p>
<dl> <dl>
<dt>[<em>Note:</em> implementers are encouraged to provide an implementation of</dt> <dt>[<em>Note:</em> implementers are encouraged to provide an implementation of</dt>
<dd><tt class="literal"><span class="pre">distance_to</span></tt> and a <tt class="literal"><span class="pre">difference_type</span></tt> that avoids overflows in <dd><tt class="literal"><span class="pre">distance_to</span></tt> and a <tt class="literal"><span class="pre">difference_type</span></tt> that avoids overflows in
@ -83,27 +95,28 @@ the cases when the <tt class="literal"><span class="pre">Incrementable</span></t
<div class="section" id="counting-iterator-requirements"> <div class="section" id="counting-iterator-requirements">
<h1><a class="toc-backref" href="#id3" name="counting-iterator-requirements"><tt class="literal"><span class="pre">counting_iterator</span></tt> requirements</a></h1> <h1><a class="toc-backref" href="#id3" name="counting-iterator-requirements"><tt class="literal"><span class="pre">counting_iterator</span></tt> requirements</a></h1>
<p>The <tt class="literal"><span class="pre">Incrementable</span></tt> type must be Default Constructible, Copy <p>The <tt class="literal"><span class="pre">Incrementable</span></tt> type must be Default Constructible, Copy
Constructible, and Assignable. The default distance is Constructible, and Assignable.</p>
an implementation defined signed integral type.</p>
</div> </div>
<div class="section" id="counting-iterator-models"> <div class="section" id="counting-iterator-models">
<h1><a class="toc-backref" href="#id4" name="counting-iterator-models"><tt class="literal"><span class="pre">counting_iterator</span></tt> models</a></h1> <h1><a class="toc-backref" href="#id4" name="counting-iterator-models"><tt class="literal"><span class="pre">counting_iterator</span></tt> models</a></h1>
<p><tt class="literal"><span class="pre">counting_iterator</span></tt> models Readable Lvalue Iterator.</p> <p><tt class="literal"><span class="pre">counting_iterator</span></tt> models Readable Lvalue Iterator.</p>
<p>Furthermore, if you wish to create a counting iterator that is a Forward <p>Furthermore, if you wish to create a counting iterator that is a
Traversal Iterator, then the following expressions must be valid:</p> Forward Traversal Iterator and also Forward Iterator, then the
following expressions must be valid:</p>
<pre class="literal-block"> <pre class="literal-block">
Incrementable i, j; Incrementable i, j;
++i // pre-increment ++i // pre-increment
i == j // operator equal i == j // operator equal
</pre> </pre>
<p>If you wish to create a counting iterator that is a <p>If you wish to create a counting iterator that is a Bidirectional
Bidirectional Traversal Iterator, then pre-decrement is also required:</p> Traversal Iterator and also Bidirectional Iterator, then pre-decrement
is also required:</p>
<pre class="literal-block"> <pre class="literal-block">
--i --i
</pre> </pre>
<p>If you wish to create a counting iterator that is a Random Access <p>If you wish to create a counting iterator that is a Random Access
Traversal Iterator, then these additional expressions are also Traversal Iterator and also Random Access Iterator, then these
required:</p> additional expressions are also required:</p>
<pre class="literal-block"> <pre class="literal-block">
counting_iterator::difference_type n; counting_iterator::difference_type n;
i += n i += n
@ -235,7 +248,7 @@ indirectly printing out the numbers from 0 to 7
<hr class="footer"/> <hr class="footer"/>
<div class="footer"> <div class="footer">
<a class="reference" href="counting_iterator.rst">View document source</a>. <a class="reference" href="counting_iterator.rst">View document source</a>.
Generated on: 2004-01-12 16:05 UTC. Generated on: 2004-01-12 19:01 UTC.
Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source. Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
</div> </div>
</body> </body>

View File

@ -8,6 +8,12 @@
class counting_iterator class counting_iterator
{ {
public: public:
typedef Incrementable value_type;
typedef const Incrementable& reference;
typedef const Incrementable* pointer;
typedef /* see below */ difference_type;
typedef /* see below */ iterator_category;
counting_iterator(); counting_iterator();
counting_iterator(counting_iterator const& rhs); counting_iterator(counting_iterator const& rhs);
explicit counting_iterator(Incrementable x); explicit counting_iterator(Incrementable x);
@ -20,6 +26,15 @@
}; };
If the ``Diference`` argument is ``use_default`` then the
``difference_type`` member is an implementation defined signed
integral type.
The member ``iterator_category`` is a type that satisfies the
requirements of the concepts modeled by the ``counting_iterator`` as
specified in the models section.
[*Note:* implementers are encouraged to provide an implementation of [*Note:* implementers are encouraged to provide an implementation of
``distance_to`` and a ``difference_type`` that avoids overflows in ``distance_to`` and a ``difference_type`` that avoids overflows in
the cases when the ``Incrementable`` type is a numeric type.] the cases when the ``Incrementable`` type is a numeric type.]
@ -28,8 +43,7 @@
.................................. ..................................
The ``Incrementable`` type must be Default Constructible, Copy The ``Incrementable`` type must be Default Constructible, Copy
Constructible, and Assignable. The default distance is Constructible, and Assignable.
an implementation defined signed integral type.
``counting_iterator`` models ``counting_iterator`` models
@ -37,21 +51,23 @@ an implementation defined signed integral type.
``counting_iterator`` models Readable Lvalue Iterator. ``counting_iterator`` models Readable Lvalue Iterator.
Furthermore, if you wish to create a counting iterator that is a Forward Furthermore, if you wish to create a counting iterator that is a
Traversal Iterator, then the following expressions must be valid:: Forward Traversal Iterator and also Forward Iterator, then the
following expressions must be valid::
Incrementable i, j; Incrementable i, j;
++i // pre-increment ++i // pre-increment
i == j // operator equal i == j // operator equal
If you wish to create a counting iterator that is a If you wish to create a counting iterator that is a Bidirectional
Bidirectional Traversal Iterator, then pre-decrement is also required:: Traversal Iterator and also Bidirectional Iterator, then pre-decrement
is also required::
--i --i
If you wish to create a counting iterator that is a Random Access If you wish to create a counting iterator that is a Random Access
Traversal Iterator, then these additional expressions are also Traversal Iterator and also Random Access Iterator, then these
required:: additional expressions are also required::
counting_iterator::difference_type n; counting_iterator::difference_type n;
i += n i += n

View File

@ -1327,9 +1327,9 @@ if (Difference is use_default)
else else
typedef Difference difference_type; typedef Difference difference_type;
</pre> </pre>
<p>The member <tt class="literal"><span class="pre">indirect_iterator::iterator_category</span></tt> is a type that <p>The member <tt class="literal"><span class="pre">iterator_category</span></tt> is a type that satisfies the
satisfies the requirements of the concepts modeled by the indirect requirements of the concepts modeled by the <tt class="literal"><span class="pre">indirect_iterator</span></tt> as
iterator as specified in the models section.</p> specified in the models section.</p>
</div> </div>
<div class="section" id="indirect-iterator-requirements"> <div class="section" id="indirect-iterator-requirements">
<h4><a class="toc-backref" href="#id43" name="indirect-iterator-requirements"><tt class="literal"><span class="pre">indirect_iterator</span></tt> requirements</a></h4> <h4><a class="toc-backref" href="#id43" name="indirect-iterator-requirements"><tt class="literal"><span class="pre">indirect_iterator</span></tt> requirements</a></h4>
@ -2061,6 +2061,12 @@ template &lt;
class counting_iterator class counting_iterator
{ {
public: public:
typedef Incrementable value_type;
typedef const Incrementable&amp; reference;
typedef const Incrementable* pointer;
typedef /* see below */ difference_type;
typedef /* see below */ iterator_category;
counting_iterator(); counting_iterator();
counting_iterator(counting_iterator const&amp; rhs); counting_iterator(counting_iterator const&amp; rhs);
explicit counting_iterator(Incrementable x); explicit counting_iterator(Incrementable x);
@ -2072,6 +2078,12 @@ class counting_iterator
Incrementable m_inc; // exposition Incrementable m_inc; // exposition
}; };
</pre> </pre>
<p>If the <tt class="literal"><span class="pre">Diference</span></tt> argument is <tt class="literal"><span class="pre">use_default</span></tt> then the
<tt class="literal"><span class="pre">difference_type</span></tt> member is an implementation defined signed
integral type.</p>
<p>The member <tt class="literal"><span class="pre">iterator_category</span></tt> is a type that satisfies the
requirements of the concepts modeled by the <tt class="literal"><span class="pre">counting_iterator</span></tt> as
specified in the models section.</p>
<dl> <dl>
<dt>[<em>Note:</em> implementers are encouraged to provide an implementation of</dt> <dt>[<em>Note:</em> implementers are encouraged to provide an implementation of</dt>
<dd><tt class="literal"><span class="pre">distance_to</span></tt> and a <tt class="literal"><span class="pre">difference_type</span></tt> that avoids overflows in <dd><tt class="literal"><span class="pre">distance_to</span></tt> and a <tt class="literal"><span class="pre">difference_type</span></tt> that avoids overflows in
@ -2081,27 +2093,28 @@ the cases when the <tt class="literal"><span class="pre">Incrementable</span></t
<div class="section" id="counting-iterator-requirements"> <div class="section" id="counting-iterator-requirements">
<h4><a class="toc-backref" href="#id63" name="counting-iterator-requirements"><tt class="literal"><span class="pre">counting_iterator</span></tt> requirements</a></h4> <h4><a class="toc-backref" href="#id63" name="counting-iterator-requirements"><tt class="literal"><span class="pre">counting_iterator</span></tt> requirements</a></h4>
<p>The <tt class="literal"><span class="pre">Incrementable</span></tt> type must be Default Constructible, Copy <p>The <tt class="literal"><span class="pre">Incrementable</span></tt> type must be Default Constructible, Copy
Constructible, and Assignable. The default distance is Constructible, and Assignable.</p>
an implementation defined signed integral type.</p>
</div> </div>
<div class="section" id="counting-iterator-models"> <div class="section" id="counting-iterator-models">
<h4><a class="toc-backref" href="#id64" name="counting-iterator-models"><tt class="literal"><span class="pre">counting_iterator</span></tt> models</a></h4> <h4><a class="toc-backref" href="#id64" name="counting-iterator-models"><tt class="literal"><span class="pre">counting_iterator</span></tt> models</a></h4>
<p><tt class="literal"><span class="pre">counting_iterator</span></tt> models Readable Lvalue Iterator.</p> <p><tt class="literal"><span class="pre">counting_iterator</span></tt> models Readable Lvalue Iterator.</p>
<p>Furthermore, if you wish to create a counting iterator that is a Forward <p>Furthermore, if you wish to create a counting iterator that is a
Traversal Iterator, then the following expressions must be valid:</p> Forward Traversal Iterator and also Forward Iterator, then the
following expressions must be valid:</p>
<pre class="literal-block"> <pre class="literal-block">
Incrementable i, j; Incrementable i, j;
++i // pre-increment ++i // pre-increment
i == j // operator equal i == j // operator equal
</pre> </pre>
<p>If you wish to create a counting iterator that is a <p>If you wish to create a counting iterator that is a Bidirectional
Bidirectional Traversal Iterator, then pre-decrement is also required:</p> Traversal Iterator and also Bidirectional Iterator, then pre-decrement
is also required:</p>
<pre class="literal-block"> <pre class="literal-block">
--i --i
</pre> </pre>
<p>If you wish to create a counting iterator that is a Random Access <p>If you wish to create a counting iterator that is a Random Access
Traversal Iterator, then these additional expressions are also Traversal Iterator and also Random Access Iterator, then these
required:</p> additional expressions are also required:</p>
<pre class="literal-block"> <pre class="literal-block">
counting_iterator::difference_type n; counting_iterator::difference_type n;
i += n i += n
@ -2308,7 +2321,7 @@ LocalWords: OtherIncrementable Coplien -->
<hr class="footer"/> <hr class="footer"/>
<div class="footer"> <div class="footer">
<a class="reference" href="facade-and-adaptor.rst">View document source</a>. <a class="reference" href="facade-and-adaptor.rst">View document source</a>.
Generated on: 2004-01-12 18:37 UTC. Generated on: 2004-01-12 19:01 UTC.
Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source. Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
</div> </div>
</body> </body>

View File

@ -125,9 +125,9 @@ if (Difference is use_default)
else else
typedef Difference difference_type; typedef Difference difference_type;
</pre> </pre>
<p>The member <tt class="literal"><span class="pre">indirect_iterator::iterator_category</span></tt> is a type that <p>The member <tt class="literal"><span class="pre">iterator_category</span></tt> is a type that satisfies the
satisfies the requirements of the concepts modeled by the indirect requirements of the concepts modeled by the <tt class="literal"><span class="pre">indirect_iterator</span></tt> as
iterator as specified in the models section.</p> specified in the models section.</p>
</div> </div>
<div class="section" id="indirect-iterator-requirements"> <div class="section" id="indirect-iterator-requirements">
<h1><a class="toc-backref" href="#id3" name="indirect-iterator-requirements"><tt class="literal"><span class="pre">indirect_iterator</span></tt> requirements</a></h1> <h1><a class="toc-backref" href="#id3" name="indirect-iterator-requirements"><tt class="literal"><span class="pre">indirect_iterator</span></tt> requirements</a></h1>
@ -315,7 +315,7 @@ a,b,c,d,e,f,g,
<hr class="footer"/> <hr class="footer"/>
<div class="footer"> <div class="footer">
<a class="reference" href="indirect_iterator.rst">View document source</a>. <a class="reference" href="indirect_iterator.rst">View document source</a>.
Generated on: 2004-01-12 16:04 UTC. Generated on: 2004-01-12 19:01 UTC.
Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source. Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
</div> </div>
</body> </body>

View File

@ -67,9 +67,9 @@ following pseudo-code. We use the abbreviation
typedef Difference difference_type; typedef Difference difference_type;
The member ``indirect_iterator::iterator_category`` is a type that The member ``iterator_category`` is a type that satisfies the
satisfies the requirements of the concepts modeled by the indirect requirements of the concepts modeled by the ``indirect_iterator`` as
iterator as specified in the models section. specified in the models section.
``indirect_iterator`` requirements ``indirect_iterator`` requirements

View File

@ -271,7 +271,11 @@ The description of Counting iterator is unclear. "The counting iterator adaptor
dereference by returning a reference to the base object. The other operations are implemented by dereference by returning a reference to the base object. The other operations are implemented by
the base m_iterator, as per the inheritance from iterator_adaptor." the base m_iterator, as per the inheritance from iterator_adaptor."
:Proposed resolution: **Needs work** (Jeremy) Reword. :Proposed resolution:
Change the introduction to: ``counting_iterator`` adapts an
arithmetic type, such as ``int``, by adding an ``operator*`` that
returns the current value of the object.
9.14 Counting_iterator's difference type 9.14 Counting_iterator's difference type
@ -290,8 +294,11 @@ I'm not sure what this means. The user provides a template argument named Differ
there's no difference_type. I assume this is just a glitch in the wording. But if implementors are there's no difference_type. I assume this is just a glitch in the wording. But if implementors are
encouraged to ignore this argument if it won't work right, why is it there? encouraged to ignore this argument if it won't work right, why is it there?
:Proposed resolution: **Needs work** (Jeremy) :Proposed resolution:
Reword. The ``difference_type`` was inherited from ``iterator_adaptor``.
However, we've removed the explicit inheritance, so explicit typedefs have
been added.
9.15 How to detect lvalueness? 9.15 How to detect lvalueness?