<HTML><HEAD><TITLE>N1672=04-0112, Adapting N1640 To C++0x</TITLE></HEAD><BODY>

<CENTER>
<H1><A NAME="Adapting N1640 To C++0x">Adapting N1640 To C++0x</A></H1>
</CENTER>

<TABLE ALIGN="RIGHT" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD ALIGN="RIGHT"><B><I>Document number:</I></B></TD>
<TD>&nbsp; N1672=04-0112</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Date:</I></B></TD>
<TD>&nbsp; September 10, 2004</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Project:</I></B></TD>
<TD>&nbsp; Programming Language C++</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Reference:</I></B></TD>
<TD>&nbsp; ISO/IEC IS 14882:2003(E)</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Reply to:</I></B></TD>
<TD>&nbsp; Pete Becker</TD>
</TR>
<TR>
<TD></TD>
<TD>&nbsp; Dinkumware, Ltd.</TD>
</TR>
<TR>
<TD></TD>
<TD>&nbsp; petebecker@acm.org</TD>
</TR>
</TABLE>
<BR CLEAR="ALL">

<HR>

<P><B><CODE><A HREF="#Introduction">Introduction</A>
&#183; <A HREF="#Changes to Iterator Categories">Changes to Iterator Categories</A>
&#183; <A HREF="#Changes to Algorithms">Changes to Algorithms</A>
&#183; <A HREF="#Changes to Containers">Changes to Containers</A>
&#183; <A HREF="#Impact on Existing Code">Impact on Existing Code</A>
</CODE></B></P>

<HR>

<H2><A NAME="Introduction">Introduction</A></H2>

<P>The underlying idea in the paper <I>New Iterator Concepts</I> (N1640=04-0080)
is fairly simple: separating dereferencing of iterators from traversing them
provides more flexibility for programmers who implement and use iterators. The
details in the paper are somewhat complicated, however, because the paper
creates a new set of iterator requirements while attempting to make these new
requirements compatible with the existing iterator requirements. Applying the
underlying idea directly to the existing iterator requirements is much simpler.</P>

<H2><A NAME="Changes to Iterator Categories">Changes to Iterator Categories</A></H2>

<P>The current iterator categories look like this:</P>

<TABLE ALIGN="CENTER" BORDER="ALL">
<TR>
    <TH>Category</TH>
    <TH>Traversal Properties</TH>
    <TH>Access</TH>
    <TH>Tag</TH>
</TR>
<TR>
    <TD>output iterator</TD>
    <TD>destructive increment</TD>
    <TD>writable</TD>
    <TD><CODE>output_iterator_tag</CODE></TD>
</TR>
<TR>
    <TD>input iterator</TD>
    <TD>destructive increment, compare</TD>
    <TD>readable</TD>
    <TD><CODE>input_iterator_tag</CODE></TD>
</TR>
<TR>
    <TD>forward iterator</TD>
    <TD>increment, compare</TD>
    <TD>readable or writable</TD>
    <TD><CODE>forward_iterator_tag</CODE></TD>
</TR>
<TR>
    <TD>bidirectional iterator</TD>
    <TD>forward iterator properties plus decrement</TD>
    <TD>readable or writable</TD>
    <TD><CODE>bidirectional_iterator_tag</CODE></TD>
</TR>
<TR>
    <TD>random access iterator</TD>
    <TD>bidirectional iterator properties plus random access</TD>
    <TD>readable or writable</TD>
    <TD><CODE>random_access_iterator_tag</CODE></TD>
</TR>
</TABLE>

<P>N1640 proposes adding the following categories:</P>

<TABLE ALIGN="CENTER" BORDER="ALL">
<TR>
    <TH>Category</TH>
    <TH>Traversal Properties</TH>
    <TH>Tag</TH>
</TR>
<TR>
    <TD>incrementable iterator</TD>
    <TD>destructive increment</TD>
    <TD><CODE>incrementable_traversal_tag</CODE></TD>
</TR>
<TR>
    <TD>single pass iterator</TD>
    <TD>destructive increment, compare</TD>
    <TD><CODE>single_pass_traversal_tag</CODE></TD>
</TR>
<TR>
    <TD>forward traversal iterator</TD>
    <TD>increment, compare</TD>
    <TD><CODE>forward_traversal_tag</CODE></TD>
</TR>
<TR>
    <TD>bidirectional traversal iterator</TD>
    <TD>forward traversal iterator properties plus decrement</TD>
    <TD><CODE>bidirectional_traversal_tag</CODE></TD>
</TR>
<TR>
    <TD>random access traversal iterator</TD>
    <TD>bidrectional traversal iterator properties plus random access</TD>
    <TD><CODE>random_access_traversal_tag</CODE></TD>
</TR>
</TABLE>

<P>This paper proposes removing the access properties from the current iterator
categories, as proposed in N1640, but for the most part keeping the names and
tag types from the current categories:</P>

<TABLE ALIGN="CENTER" BORDER="ALL">
<TR>
    <TH>Category</TH>
    <TH>Traversal Properties</TH>
    <TH>Tag</TH>
    <TH>Tag Typedef</TH>
</TR>
<TR>
    <TD>incrementable iterator</TD>
    <TD>destructive increment</TD>
    <TD><CODE>incremental_iterator_tag</CODE></TD>
    <TD><CODE>output_iterator_tag</CODE></TD>
</TR>
<TR>
    <TD>single pass iterator</TD>
    <TD>destructive increment, compare</TD>
    <TD><CODE>single_pass_iterator_tag</CODE></TD>
    <TD><CODE>input_iterator_tag</CODE></TD>
</TR>
<TR>
    <TD>forward iterator</TD>
    <TD>increment, compare</TD>
    <TD><CODE>forward_iterator_tag</CODE></TD>
    <TD>&nbsp;</TD>
</TR>
<TR>
    <TD>bidirectional iterator</TD>
    <TD>forward iterator properties plus decrement</TD>
    <TD><CODE>bidirectional_iterator_tag</CODE></TD>
    <TD>&nbsp;</TD>
</TR>
<TR>
    <TD>random access iterator</TD>
    <TD>bidirectional iterator properties plus random access</TD>
    <TD><CODE>random_access_iterator_tag</CODE></TD>
    <TD>&nbsp;</TD>
</TR>
</TABLE>

<P>As in N1640, each of the tags is derived from the tag in the row above it.
The tags <CODE>output_iterator_tag</CODE> and <CODE>input_iterator_tag</CODE>
become typedefs for <CODE>incremental_iterator_tag</CODE> and
<CODE>single_pass_iterator_tag</CODE>, respectively.</P>

<H2><A NAME="Changes to Algorithms">Changes to Algorithms</A></H2>

<P>As discussed in N1640, changing the iterator categories so that they no longer
reflect access properties means that algorithms can no longer be specified
solely in terms of the iterator categories that they accept. Algorithms
must also specify the access properties that they require for each of the
iterator types that they take.</P>

<H2><A NAME="Changes to Containers">Changes to Containers</A></H2>

<P>Obversely, changing the iterator categories means that member functions that
return iterators into containers can no longer be specified solely in terms
of the iterator categories of the iterators that they return. They must also
specify the access properties of those iterators.</P>

<H2><A NAME="Impact on Existing Code">Impact on Existing Code</A></H2>

<P>None.</P>

<P>Okay, that's a bit glib. But these changes affect only the way that we describe
iterators, algorithms, and containers, not the way any of them are currently
implemented. So all existing valid code remains valid.</P>

<P>At first glance there does appear to be a possible problem from the reduced
guarantees that the new iterator categories make. Algorithms often have multiple
implementations, chosen according to the properties of the types of the iterators
that they are called with. Reducing the guarantees for an iterator category means that
algorithms that rely on properties that are no longer required for a particular
category will no longer work correctly.</P>

<P>However, removing access properties from iterator categories has no such
impact. 
An algorithm's requirements for readability and writability of iterators
are absolute requirements, not iterator properties whose absence can be worked around.
Algorithms do not provide alternate formulations depending on whether the iterator
they are called with is readable. They simply fail to compile.</P>

</BODY></HTML>
