diff --git a/operators.htm b/operators.htm index e664a95..18434d9 100644 --- a/operators.htm +++ b/operators.htm @@ -50,6 +50,7 @@ provided by the class.
There are three separate iterator helper classes, each for a +
There are five separate iterator helper classes, each for a
different category of iterator. Here is a summary of the core set of
operators that the custom iterator must define, and the extra operators
that are created by the helper classes. These classes cannot be used for iterator_category, [1] Unlike other iterator helpers templates,
+ [2] As self-proxying is the easiest and most common way to
+implement output iterators (see, for example, insert [24.4.2] and stream
+iterators [24.5] in the standard library), Note that support for self-proxying does not prevent you from using The iterators_test.cpp
@@ -1092,7 +1142,7 @@ the library remain backward-compatible. Revised: 20 May 2001 Revised: 25 Jun 2001 Copyright © David Abrahams and Beman Dawes 1999-2001.
Permission to copy, use, modify, sell and distribute this document is
value_type
,
-
+ output_iterator_helper<T, V, D, P, R>
output_iterator_helper<T>
Supports the operations and has the requirements of
+
+ See also [1], [2].
+
+
@@ -975,6 +978,53 @@ C++ standard (forward_iterator_helper<T, V, D, P, R>
iterator_category
, value_type
,
Iterator Helper Notes
+
+output_iterator_helper
takes only one template parameter - the type of
+its target class. Although to some it might seem like an unnecessary
+restriction, the standard requires difference_type
and
+value_type
of any output iterator to be
+void
(24.3.1 [lib.iterator.traits]), and
+output_iterator_helper
template respects this
+requirement. Also, output iterators in the standard have void pointer and
+reference types, so the output_iterator_helper does the
+same.
+
+output_iterator_helper
+supports the idiom by defining operator*
+and operator++
member functions which just return a
+non-const reference to the iterator itself. Support for
+self-proxying allows us, in many cases, to reduce the task of writing an output
+iterator to writing just two member functions - an appropriate
+constructor and a copy-assignment operator. For example, here is a possible
+implementation of boost::function_output_iterator
+adaptor:
+template<class UnaryFunction>
+struct function_output_iterator
+ : boost::output_iterator_helper< function_output_iterator<UnaryFunction> >
+{
+ explicit function_output_iterator(UnaryFunction const& f = UnaryFunction())
+ : func(f) {}
+
+ template<typename T>
+ function_output_iterator& operator=(T const& value)
+ {
+ this->func(value);
+ return *this;
+ }
+
+ private:
+ UnaryFunction func;
+};
+
+
+output_iterator_helper
to ease any other, different kind of output iterator's implementation. If output_iterator_helper
's target type provides its own definition of operator*
or/and operator++
, then these operators will get used and the ones supplied by output_iterator_helper
will never be instantiated.Iterator Demonstration and Test Program
-