<metaname="author"content="David Abrahams, Jeremy Siek, Thomas Witt"/>
<metaname="organization"content="Boost Consulting, Indiana University Open Systems Lab, University of Hanover Institute for Transport Railway Operation and Construction"/>
<td><aclass="first reference"href="http://www.boost-consulting.com">Boost Consulting</a>, Indiana University <aclass="reference"href="http://www.osl.iu.edu">Open Systems
Lab</a>, University of Hanover <aclass="last reference"href="http://www.ive.uni-hannover.de">Institute for Transport
<trclass="field"><thclass="docinfo-name">Number:</th><tdclass="field-body">This is a revised version of <aclass="reference"href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1530.html">N1530</a>=03-0113, which was
accepted for Technical Report 1 by the C++ standard
committee's library working group.</td>
</tr>
</tbody>
</table>
<!-- Version 1.9 of this ReStructuredText document corresponds to
n1530_, the paper accepted by the LWG. -->
<tableclass="field-list"frame="void"rules="none">
<colclass="field-name"/>
<colclass="field-body"/>
<tbodyvalign="top">
<trclass="field"><thclass="field-name">copyright:</th><tdclass="field-body">Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved</td>
<li><aclass="reference"href="#iterator-adaptor-base-class-parameters"id="id34"name="id34"><ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> base class parameters</a></li>
<li><aclass="reference"href="#iterator-adaptor-public-operations"id="id36"name="id36"><ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> public operations</a></li>
<li><aclass="reference"href="#iterator-adaptor-protected-member-functions"id="id37"name="id37"><ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> protected member functions</a></li>
<li><aclass="reference"href="#iterator-adaptor-private-member-functions"id="id38"name="id38"><ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> private member functions</a></li>
<li><aclass="reference"href="#transform-iterator-public-operations"id="id50"name="id50"><ttclass="literal"><spanclass="pre">transform_iterator</span></tt> public operations</a></li>
as proposed in <aclass="reference"href="http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/papers/2003/n1550.html">n1550</a>, since user-defined and especially adapted
<p>This proposal does not strictly depend on proposal <aclass="reference"href="http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/papers/2003/n1550.html">n1550</a>, as there
could be reformulated using this mapping if <aclass="reference"href="http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/papers/2003/n1550.html">n1550</a> was not accepted.</p>
<p>The question of iterator interoperability is poorly addressed in the
current standard. There are currently two defect reports that are
concerned with interoperability issues.</p>
<p>Issue <aclass="reference"href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#179">179</a> concerns the fact that mutable container iterator types
are only required to be convertible to the corresponding constant
iterator types, but objects of these types are not required to
interoperate in comparison or subtraction expressions. This situation
is tedious in practice and out of line with the way built in types
work. This proposal implements the proposed resolution to issue
<aclass="reference"href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#179">179</a>, as most standard library implementations do nowadays. In other
words, if an iterator type A has an implicit or user defined
conversion to an iterator type B, the iterator types are interoperable
and the usual set of operators are available.</p>
<p>Issue <aclass="reference"href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#280">280</a> concerns the current lack of interoperability between
reverse iterator types. The proposed new reverse_iterator template
fixes the issues raised in 280. It provides the desired
interoperability without introducing unwanted overloads.</p>
<p>While the iterator interface is rich, there is a core subset of the
interface that is necessary for all the functionality. We have
identified the following core behaviors for iterators:</p>
<ulclass="simple">
<li>dereferencing</li>
<li>incrementing</li>
<li>decrementing</li>
<li>equality comparison</li>
<li>random-access motion</li>
<li>distance measurement</li>
</ul>
<p>In addition to the behaviors listed above, the core interface elements
include the associated types exposed through iterator traits:
<ttclass="literal"><spanclass="pre">value_type</span></tt>, <ttclass="literal"><spanclass="pre">reference</span></tt>, <ttclass="literal"><spanclass="pre">difference_type</span></tt>, and
class as the first template parameter. The order of the other
template parameters to <ttclass="literal"><spanclass="pre">iterator_facade</span></tt> have been carefully chosen
to take advantage of useful defaults. For example, when defining a
constant lvalue iterator, the user can pass a const-qualified version
of the iterator's <ttclass="literal"><spanclass="pre">value_type</span></tt> as <ttclass="literal"><spanclass="pre">iterator_facade</span></tt>'s <ttclass="literal"><spanclass="pre">Value</span></tt>
parameter and omit the <ttclass="literal"><spanclass="pre">Reference</span></tt> parameter which follows.</p>
<p>The derived iterator class must define member functions implementing
the iterator's core behaviors. The following table describes
expressions which are required to be valid depending on the category
of the derived iterator type. These member functions are described
<td>Measure the distance to <ttclass="literal"><spanclass="pre">j</span></tt></td>
</tr>
</tbody>
</table>
</blockquote>
<!-- Should we add a comment that a zero overhead implementation of iterator_facade
is possible with proper inlining? -->
<p>In addition to implementing the core interface functions, an iterator
derived from <ttclass="literal"><spanclass="pre">iterator_facade</span></tt> typically defines several
constructors. To model any of the standard iterator concepts, the
iterator must at least have a copy constructor. Also, if the iterator
type <ttclass="literal"><spanclass="pre">X</span></tt> is meant to be automatically interoperate with another
iterator type <ttclass="literal"><spanclass="pre">Y</span></tt> (as with constant and mutable iterators) then
there must be an implicit conversion from <ttclass="literal"><spanclass="pre">X</span></tt> to <ttclass="literal"><spanclass="pre">Y</span></tt> or from <ttclass="literal"><spanclass="pre">Y</span></tt>
to <ttclass="literal"><spanclass="pre">X</span></tt> (but not both), typically implemented as a conversion
constructor. Finally, if the iterator is to model Forward Traversal
Iterator or a more-refined iterator concept, a default constructor is
member (e.g. <aclass="reference"href="#counting"><ttclass="literal"><spanclass="pre">counting_iterator</span></tt></a>), because <ttclass="literal"><spanclass="pre">*(p+n)</span></tt> is a reference
<p>Writable iterators built with <ttclass="literal"><spanclass="pre">iterator_facade</span></tt> implement the
semantics required by the preferred resolution to <aclass="reference"href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#299">issue 299</a> and
adopted by proposal <aclass="reference"href="http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/papers/2003/n1550.html">n1550</a>: the result of <ttclass="literal"><spanclass="pre">p[n]</span></tt> is a proxy object
containing a copy of <ttclass="literal"><spanclass="pre">p+n</span></tt>, and <ttclass="literal"><spanclass="pre">p[n]</span><spanclass="pre">=</span><spanclass="pre">x</span></tt> is equivalent to <ttclass="literal"><spanclass="pre">*(p</span>
<spanclass="pre">+</span><spanclass="pre">n)</span><spanclass="pre">=</span><spanclass="pre">x</span></tt>. This approach will work properly for any random-access
iterator regardless of the other details of its implementation. A
user who knows more about the implementation of her iterator is free
to implement an <ttclass="literal"><spanclass="pre">operator[]</span></tt> which returns an lvalue in the derived
iterator class; it will hide the one supplied by <ttclass="literal"><spanclass="pre">iterator_facade</span></tt>
<p>The <ttclass="literal"><spanclass="pre">reference</span></tt> type of a readable iterator (and today's input
iterator) need not in fact be a reference, so long as it is
convertible to the iterator's <ttclass="literal"><spanclass="pre">value_type</span></tt>. When the <ttclass="literal"><spanclass="pre">value_type</span></tt>
is a class, however, it must still be possible to access members
through <ttclass="literal"><spanclass="pre">operator-></span></tt>. Therefore, an iterator whose <ttclass="literal"><spanclass="pre">reference</span></tt>
type is not in fact a reference must return a proxy containing a copy
of the referenced value from its <ttclass="literal"><spanclass="pre">operator-></span></tt>.</p>
<p>The return type for <ttclass="literal"><spanclass="pre">operator-></span></tt> and <ttclass="literal"><spanclass="pre">operator[]</span></tt> is not
explicitly specified. Instead it requires each <ttclass="literal"><spanclass="pre">iterator_facade</span></tt>
<!-- Version 1.2 of this ReStructuredText document corresponds to
n1530_, the paper accepted by the LWG for TR1. -->
<!-- Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All
rights reserved -->
<p>The <ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> class template adapts some <ttclass="literal"><spanclass="pre">Base</span></tt><aclass="footnote-reference"href="#base"id="id7"name="id7"><sup>3</sup></a>
<p>This proposal also contains several examples of specialized adaptors
which were easily implemented using <ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt>:</p>
<ulclass="simple">
<li><ttclass="literal"><spanclass="pre">indirect_iterator</span></tt>, which iterates over iterators, pointers,
or smart pointers and applies an extra level of dereferencing.</li>
<li>A new <ttclass="literal"><spanclass="pre">reverse_iterator</span></tt>, which inverts the direction of a Base
iterator's motion, while allowing adapted constant and mutable
iterators to interact in the expected ways (unlike those in most
implementations of C++98).</li>
<li><ttclass="literal"><spanclass="pre">transform_iterator</span></tt>, which applies a user-defined function object
to the underlying values when dereferenced.</li>
<li><ttclass="literal"><spanclass="pre">projection_iterator</span></tt>, which is similar to <ttclass="literal"><spanclass="pre">transform_iterator</span></tt>
except that when dereferenced it returns a reference instead of
a value.</li>
<li><ttclass="literal"><spanclass="pre">filter_iterator</span></tt>, which provides a view of an iterator range in
which some elements of the underlying range are skipped.</li>
<p>The <ttclass="literal"><spanclass="pre">enable_if_interoperable</span></tt> template used above is for exposition
purposes. The member operators should be only be in an overload set
provided the derived types <ttclass="literal"><spanclass="pre">Dr1</span></tt> and <ttclass="literal"><spanclass="pre">Dr2</span></tt> are interoperable,
meaning that at least one of the types is convertible to the other. The
<p>In the table below, <ttclass="literal"><spanclass="pre">F</span></tt> is <ttclass="literal"><spanclass="pre">iterator_facade<X,V,C,R,D></span></tt>, <ttclass="literal"><spanclass="pre">a</span></tt> is an
object of type <ttclass="literal"><spanclass="pre">X</span></tt>, <ttclass="literal"><spanclass="pre">b</span></tt> and <ttclass="literal"><spanclass="pre">c</span></tt> are objects of type <ttclass="literal"><spanclass="pre">const</span><spanclass="pre">X</span></tt>,
<ttclass="literal"><spanclass="pre">n</span></tt> is an object of <ttclass="literal"><spanclass="pre">F::difference_type</span></tt>, <ttclass="literal"><spanclass="pre">y</span></tt> is a constant
object of a single pass iterator type interoperable with <ttclass="literal"><spanclass="pre">X</span></tt>, and <ttclass="literal"><spanclass="pre">z</span></tt>
<spanclass="pre"><=</span><spanclass="pre">z</span></tt>, <ttclass="literal"><spanclass="pre">c</span><spanclass="pre">></span><spanclass="pre">z</span></tt>, and <ttclass="literal"><spanclass="pre">c</span><spanclass="pre">>=</span><spanclass="pre">c</span></tt>.</td>
<p>The <ttclass="literal"><spanclass="pre">iterator_category</span></tt> member of <ttclass="literal"><spanclass="pre">iterator_facade<X,V,R,C,D></span></tt>
is a type which satisfies the following conditions:</p>
<blockquote>
<ul>
<li><pclass="first">if <ttclass="literal"><spanclass="pre">C</span></tt> is convertible to <ttclass="literal"><spanclass="pre">std::input_iterator_tag</span></tt> or
<ttclass="literal"><spanclass="pre">C</span></tt> is convertible to <ttclass="literal"><spanclass="pre">std::output_iterator_tag</span></tt>,
<ttclass="literal"><spanclass="pre">iterator_category</span></tt> is the same as <ttclass="literal"><spanclass="pre">C</span></tt>.</p>
</li>
<li><pclass="first">Otherwise, if <ttclass="literal"><spanclass="pre">C</span></tt> is not convertible to
<ttclass="literal"><spanclass="pre">incrementable_traversal_tag</span></tt>, the program is ill-formed</p>
</li>
<li><pclass="first">Otherwise:</p>
<ul>
<li><pclass="first"><ttclass="literal"><spanclass="pre">iterator_category</span></tt> is convertible to the iterator
category tag or tags given by the following algorithm, and
not to any more-derived iterator category tag or tags:</p>
<preclass="literal-block">
if (R is a reference type
&& C is convertible to forward_traversal_tag)
{
if (C is convertible to random_access_traversal_tag)
return random_access_iterator_tag
else if (C is convertible to bidirectional_traversal_tag)
return bidirectional_iterator_tag
else
return forward_traversal_tag
}
else
{
if (C is convertible to single_pass_traversal_tag
&& R is convertible to V)
{
if (V is const)
return input_iterator_tag
else
return input_iterator_tag and output_iterator_tag
}
else
return output_iterator_tag
}
</pre>
</li>
<li><pclass="first"><ttclass="literal"><spanclass="pre">iterator_traversal<X>::type</span></tt> is convertible to the most
derived traversal tag type to which <ttclass="literal"><spanclass="pre">C</span></tt> is also
convertible, and not to any more-derived traversal tag type.</p>
<p><ttclass="literal"><spanclass="pre">operator->()</span><spanclass="pre">const;</span></tt> (see <aclass="reference"href="#operator-arrow">below</a>)</p>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body"><pclass="first">If <ttclass="literal"><spanclass="pre">reference</span></tt> is a reference type, an object
of type <ttclass="literal"><spanclass="pre">pointer</span></tt> equal to:</p>
<pclass="last">Otherwise returns an object of unspecified type such that,
<ttclass="literal"><spanclass="pre">(*static_cast<Derived</span><spanclass="pre">const*>(this))->m</span></tt> is equivalent to <ttclass="literal"><spanclass="pre">(w</span><spanclass="pre">=</span><spanclass="pre">**static_cast<Derived</span><spanclass="pre">const*>(this),</span>
<spanclass="pre">w.m)</span></tt> for some temporary object <ttclass="literal"><spanclass="pre">w</span></tt> of type <ttclass="literal"><spanclass="pre">value_type</span></tt>.</p>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">an object convertible to <ttclass="literal"><spanclass="pre">reference</span></tt> and holding a copy
<em>p</em> of <ttclass="literal"><spanclass="pre">*static_cast<Derived</span><spanclass="pre">const*>(this)</span><spanclass="pre">+</span><spanclass="pre">n</span></tt> such that, for a constant object <ttclass="literal"><spanclass="pre">v</span></tt> of type
<ttclass="literal"><spanclass="pre">value_type</span></tt>, <ttclass="literal"><spanclass="pre">(*static_cast<Derived</span><spanclass="pre">const*>(this))[n]</span><spanclass="pre">=</span><spanclass="pre">v</span></tt> is equivalent
expected by <ttclass="literal"><spanclass="pre">iterator_facade</span></tt> are implemented in terms of the
<ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt>'s <ttclass="literal"><spanclass="pre">Base</span></tt> template parameter. A class derived
from <ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> typically redefines some of the core
interface functions to adapt the behavior of the <ttclass="literal"><spanclass="pre">Base</span></tt> type.
Whether the derived class models any of the standard iterator concepts
depends on the operations supported by the <ttclass="literal"><spanclass="pre">Base</span></tt> type and which
core interface functions of <ttclass="literal"><spanclass="pre">iterator_facade</span></tt> are redefined in the
<h3><aclass="toc-backref"href="#id34"name="iterator-adaptor-base-class-parameters"><ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> base class parameters</a></h3>
<p>The <em>V</em>, <em>C</em>, <em>R</em>, and <em>D</em> parameters of the <ttclass="literal"><spanclass="pre">iterator_facade</span></tt>
used as a base class in the summary of <ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt>
<h3><aclass="toc-backref"href="#id36"name="iterator-adaptor-public-operations"><ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> public operations</a></h3>
<trclass="field"><thclass="field-name">Requires:</th><tdclass="field-body">The <ttclass="literal"><spanclass="pre">Base</span></tt> type must be Default Constructible.</td>
</tr>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> with
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> with
<ttclass="literal"><spanclass="pre">m_iterator</span></tt> copy constructed from <ttclass="literal"><spanclass="pre">iter</span></tt>.</td>
<h3><aclass="toc-backref"href="#id37"name="iterator-adaptor-protected-member-functions"><ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> protected member functions</a></h3>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">A const reference to <ttclass="literal"><spanclass="pre">m_iterator</span></tt>.</td>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">A non-const reference to <ttclass="literal"><spanclass="pre">m_iterator</span></tt>.</td>
<h3><aclass="toc-backref"href="#id38"name="iterator-adaptor-private-member-functions"><ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> private member functions</a></h3>
<p>If <ttclass="literal"><spanclass="pre">Value</span></tt> is not <ttclass="literal"><spanclass="pre">use_default</span></tt> then the the argument for the
<ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> base class' <ttclass="literal"><spanclass="pre">Value</span></tt> parameter is <ttclass="literal"><spanclass="pre">Value</span></tt> with
cv-qualifiers removed. If <ttclass="literal"><spanclass="pre">Value</span></tt> is <ttclass="literal"><spanclass="pre">use_default</span></tt>, then the
argument for the <ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> base class' <ttclass="literal"><spanclass="pre">Value</span></tt> parameter
is computed as follows. We use the abbreviation
<ttclass="literal"><spanclass="pre">V=iterator_traits<Iterator>::value_type</span></tt> and <ttclass="literal"><spanclass="pre">v</span></tt> is an object of
type <ttclass="literal"><spanclass="pre">V</span></tt>.:</p>
<preclass="literal-block">
if (*v returns a constant lvalue or an rvalue) then
referent<V>::type
else
add_const<referent<V>::type>::type
</pre>
<p>The algorithm for the <ttclass="literal"><spanclass="pre">type</span></tt> member of <ttclass="literal"><spanclass="pre">referent</span></tt> traits class is
as follows:</p>
<preclass="literal-block">
if (Dereferenceable is a class and has member element_type)
<ttclass="literal"><spanclass="pre">iterator_traits<Iterator>::value_type</span></tt>. Let <ttclass="literal"><spanclass="pre">i</span></tt> be an object of
type <ttclass="literal"><spanclass="pre">iterator_traits<Iterator>::value_type</span></tt>. Then <ttclass="literal"><spanclass="pre">*i</span></tt> must be a
valid expression, and the type of <ttclass="literal"><spanclass="pre">*i</span></tt> must be the same as the
<ttclass="literal"><spanclass="pre">iterator_adaptor::reference</span></tt>. Also, there are further requirements
on the <ttclass="literal"><spanclass="pre">iterator_traits<Iterator>::value_type</span></tt> if the <ttclass="literal"><spanclass="pre">Value</span></tt>
parameter is not <ttclass="literal"><spanclass="pre">use_default</span></tt>, as implied by the algorithm for deducing
<trclass="field"><thclass="field-name">Requires:</th><tdclass="field-body"><ttclass="literal"><spanclass="pre">Iterator</span></tt> must be Default Constructible.</td>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">indirect_iterator</span></tt> with
a default-constructed <ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> subobject.</td>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">indirect_iterator</span></tt> with
the <ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> subobject copy constructed from <ttclass="literal"><spanclass="pre">x</span></tt>.</td>
<trclass="field"><thclass="field-name">Requires:</th><tdclass="field-body"><ttclass="literal"><spanclass="pre">Iterator2</span></tt> is implicitly convertible to <ttclass="literal"><spanclass="pre">Iterator</span></tt>.</td>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">indirect_iterator</span></tt> whose
<ttclass="literal"><spanclass="pre">iterator_adaptor</span></tt> subobject is constructed from <ttclass="literal"><spanclass="pre">y.base()</span></tt>.</td>
<trclass="field"><thclass="field-name">Requires:</th><tdclass="field-body"><ttclass="literal"><spanclass="pre">Iterator</span></tt> must be Default Constructible.</td>
</tr>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">reverse_iterator</span></tt> with a
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">reverse_iterator</span></tt> with a
base object copy constructed from <ttclass="literal"><spanclass="pre">x</span></tt>.</td>
</tr>
</tbody>
</table>
<preclass="literal-block">
template<class OtherIterator>
reverse_iterator(
reverse_iterator<OtherIterator> const& r
<trclass="field"><thclass="field-name">Requires:</th><tdclass="field-body"><ttclass="literal"><spanclass="pre">OtherIterator</span></tt> is implicitly convertible to <ttclass="literal"><spanclass="pre">Iterator</span></tt>.</td>
</tr>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">reverse_iterator</span></tt> that is a copy of <ttclass="literal"><spanclass="pre">r</span></tt>.</td>
<p>The type <ttclass="literal"><spanclass="pre">UnaryFunction</span></tt> must be Assignable, Copy Constructible, and
the expression <ttclass="literal"><spanclass="pre">f(*i)</span></tt> must be valid where <ttclass="literal"><spanclass="pre">f</span></tt> is an object of
type <ttclass="literal"><spanclass="pre">UnaryFunction</span></tt>, <ttclass="literal"><spanclass="pre">i</span></tt> is an object of type <ttclass="literal"><spanclass="pre">Iterator</span></tt>, and
where the type of <ttclass="literal"><spanclass="pre">f(*i)</span></tt> must be
<li>Writable Lvalue Iterator if <ttclass="literal"><spanclass="pre">result_of<UnaryFunction(iterator_traits<Iterator>::reference)>::type</span></tt> is a non-const reference.</li>
<li>Readable Lvalue Iterator if <ttclass="literal"><spanclass="pre">result_of<UnaryFunction(iterator_traits<Iterator>::reference)>::type</span></tt> is a const
The <ttclass="literal"><spanclass="pre">value_type</span></tt> is <ttclass="literal"><spanclass="pre">remove_cv<remove_reference<reference></span><spanclass="pre">>::type</span></tt>.</p>
<h4><aclass="toc-backref"href="#id50"name="transform-iterator-public-operations"><ttclass="literal"><spanclass="pre">transform_iterator</span></tt> public operations</a></h4>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">transform_iterator</span></tt> with <ttclass="literal"><spanclass="pre">m_f</span></tt>
and <ttclass="literal"><spanclass="pre">m_iterator</span></tt> default constructed.</td>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">transform_iterator</span></tt> with <ttclass="literal"><spanclass="pre">m_f</span></tt>
initialized to <ttclass="literal"><spanclass="pre">f</span></tt> and <ttclass="literal"><spanclass="pre">m_iterator</span></tt> initialized to <ttclass="literal"><spanclass="pre">x</span></tt>.</td>
</tr>
</tbody>
</table>
<preclass="literal-block">
template<class OtherIterator, class R2, class V2>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">transform_iterator</span></tt> that is a copy of <ttclass="literal"><spanclass="pre">t</span></tt>.</td>
</tr>
<trclass="field"><thclass="field-name">Requires:</th><tdclass="field-body"><ttclass="literal"><spanclass="pre">OtherIterator</span></tt> is implicitly convertible to <ttclass="literal"><spanclass="pre">Iterator</span></tt>.</td>
<p>The base <ttclass="literal"><spanclass="pre">Iterator</span></tt> parameter must be a model of Readable
Iterator and Single Pass Iterator. The resulting
<ttclass="literal"><spanclass="pre">filter_iterator</span></tt> will be a model of Forward Traversal Iterator
if <ttclass="literal"><spanclass="pre">Iterator</span></tt> is, otherwise the <ttclass="literal"><spanclass="pre">filter_iterator</span></tt> will be a
model of Single Pass Iterator. The access category of the
<ttclass="literal"><spanclass="pre">filter_iterator</span></tt> will be the same as the access category of
<!-- Thomas is going to try implementing filter_iterator so that
it will be bidirectional if the underlying iterator is. -JGS -->
<p>The <ttclass="literal"><spanclass="pre">Predicate</span></tt> must be Assignable, Copy Constructible, and the
expression <ttclass="literal"><spanclass="pre">p(x)</span></tt> must be valid where <ttclass="literal"><spanclass="pre">p</span></tt> is an object of type
<ttclass="literal"><spanclass="pre">Predicate</span></tt>, <ttclass="literal"><spanclass="pre">x</span></tt> is an object of type
<ttclass="literal"><spanclass="pre">iterator_traits<Iterator>::value_type</span></tt>, and where the type of
<ttclass="literal"><spanclass="pre">p(x)</span></tt> must be convertible to <ttclass="literal"><spanclass="pre">bool</span></tt>.</p>
<trclass="field"><thclass="field-name">Requires:</th><tdclass="field-body"><ttclass="literal"><spanclass="pre">Predicate</span></tt> and <ttclass="literal"><spanclass="pre">Iterator</span></tt> must be Default Constructible.</td>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">A <ttclass="literal"><spanclass="pre">filter_iterator</span></tt> at position <ttclass="literal"><spanclass="pre">x</span></tt> that filters according
to predicate <ttclass="literal"><spanclass="pre">f</span></tt> and that will not increment past <ttclass="literal"><spanclass="pre">end</span></tt>.</td>
<trclass="field"><thclass="field-name">Requires:</th><tdclass="field-body"><ttclass="literal"><spanclass="pre">Predicate</span></tt> must be Default Constructible.</td>
</tr>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">A <ttclass="literal"><spanclass="pre">filter_iterator</span></tt> at position <ttclass="literal"><spanclass="pre">x</span></tt> that filters
according to a default constructed <ttclass="literal"><spanclass="pre">Predicate</span></tt>
and that will not increment past <ttclass="literal"><spanclass="pre">end</span></tt>.</td>
</tr>
</tbody>
</table>
<preclass="literal-block">
template <class OtherIterator>
filter_iterator(
filter_iterator<Predicate, OtherIterator> const& t
<trclass="field"><thclass="field-name">Requires:</th><tdclass="field-body"><ttclass="literal"><spanclass="pre">OtherIterator</span></tt> is implicitly convertible to <ttclass="literal"><spanclass="pre">Iterator</span></tt>.</td>
</tr>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">A copy of iterator <ttclass="literal"><spanclass="pre">t</span></tt>.</td>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">A copy of the predicate object used to construct <ttclass="literal"><spanclass="pre">*this</span></tt>.</td>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">The object <ttclass="literal"><spanclass="pre">end</span></tt> used to construct <ttclass="literal"><spanclass="pre">*this</span></tt>.</td>
<dt>[<em>Note:</em> implementers are encouraged to provide an implementation of</dt>
<dd><ttclass="literal"><spanclass="pre">distance_to</span></tt> and a <ttclass="literal"><spanclass="pre">difference_type</span></tt> that avoids overflows in
the cases when the <ttclass="literal"><spanclass="pre">Incrementable</span></tt> type is a numeric type.]</dd>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">counting_iterator</span></tt> that is a copy of <ttclass="literal"><spanclass="pre">rhs</span></tt>.</td>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">counting_iterator</span></tt> with its base
object copy constructed from <ttclass="literal"><spanclass="pre">x</span></tt>.</td>
<p>The <ttclass="literal"><spanclass="pre">UnaryFunction</span></tt> must be Assignable, Copy Constructible, and the
expression <ttclass="literal"><spanclass="pre">f(x)</span></tt> must be valid, where <ttclass="literal"><spanclass="pre">f</span></tt> is an object of type
<ttclass="literal"><spanclass="pre">UnaryFunction</span></tt> and <ttclass="literal"><spanclass="pre">x</span></tt> is an object of a type accepted by <ttclass="literal"><spanclass="pre">f</span></tt>.
The resulting <ttclass="literal"><spanclass="pre">function_output_iterator</span></tt> is a model of the Writable
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">function_output_iterator</span></tt> with
<ttclass="literal"><spanclass="pre">f</span></tt> stored as a data member.</td>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">output_proxy</span></tt> constructed with
a copy of the unary function <ttclass="literal"><spanclass="pre">f</span></tt>.</td>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body">An instance of <ttclass="literal"><spanclass="pre">output_proxy</span></tt> with <ttclass="literal"><spanclass="pre">f</span></tt> stored as