diff --git a/iterator_adaptors.htm b/iterator_adaptors.htm index fe6cae2..e385520 100644 --- a/iterator_adaptors.htm +++ b/iterator_adaptors.htm @@ -155,29 +155,30 @@ struct iterator_adaptor;
-struct default_iterator_policies +struct default_iterator_policies { template <class Reference, class BaseType> Reference dereference(type<Reference>, const BaseType& x) const @@ -512,9 +513,9 @@ int main(int, char*[]) iterator_adaptor can make it easy. The rules are as follows:-
+- Adapted iterators that share the same Policies, +
- Adapted iterators that share the same Policies, Category, and Distance parameters are called - interoperable. + interoperable.
- An adapted iterator can be implicitly converted to any other adapted iterator with which it is interoperable, so long as the Base @@ -532,6 +533,52 @@ int main(int, char*[]) either order.
Example
+ +The Projection Iterator portion of this + library lets you create iterators which, when dereferenced, apply a function to the result of + dereferencing their base iterator. The projection_iterator_pair_generator template + is a special two-type generator for mutable and constant versions of a + projection iterator. It is defined as follows: +
++ ++template <class Function, class Iterator, class ConstIterator> +struct projection_iterator_pair_generator { + typedef typename AdaptableUnaryFunction::result_type value_type; + typedef projection_iterator_policies<Function> policies; +public: + typedef iterator_adaptor<Iterator,policies,value_type> iterator; + typedef iterator_adaptor<ConstIterator,policies,value_type, + const value_type&,const value_type*> type; +}; ++It is assumed that the Iterator and ConstIterator arguments are corresponding mutable +and constant iterators.
+
+- +Clearly, then, the +projection_iterator_pair_generator's iterator and +const_iterator are interoperable, since +they share the same Policies and since Category and +Distance as supplied by std::iterator_traits through the +default template parameters to +iterator_adaptor should be the same. + +
- Since Iterator can presumably be converted to +ConstIterator, the projection iterator will be convertible to +the projection const_iterator. + +
- Since projection_iterator_policies implements only the +dereference operation, and inherits all other behaviors from default_iterator_policies, which has +fully-templatized equal, less, and distance +operations, the iterator and const_iterator can be freely +mixed in comparison and subtraction expressions. + +
Challenge
There is an unlimited number of ways the the iterator_adaptors @@ -620,24 +667,24 @@ bool operator==(const iterator_adaptor<B1,P,V1,R1,P1,C,D>&,
Notes
-[1] If your compiler does not support partial - specialization and the base iterator is a builtin pointer type, then you - will not be able to use the default for Value and will need to - explicitly specify this type. - -
[2] The standard specifies that the value_type +
[1] The standard specifies that the value_type of const iterators to T (e.g. const T*) is non-const T, while the pointer and reference types for all Forward Iterators - are const T* and const T&, respectively. Stripping - the const-ness of Value is designed to allow you to - easily make a const iterator adaptor by supplying a const - type for Value, and allowing the defaults for the Pointer - and Reference parameters to take effect. Although compilers that - don't support partial specialization won't do this for you, having a + "http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterators are + const T* and const T&, respectively. Stripping the + const-ness of Value allows you to easily + make a const iterator adaptor by supplying a const type + for Value, and allowing the defaults for the Pointer and + Reference parameters to take effect. Although compilers that don't + support partial specialization won't strip const for you, having a const value_type is often harmless in practice. +
[2] If your compiler does not support partial + specialization and the base iterator is a builtin pointer type, you + will not be able to use the default for Value and will have to + specify this type explicitly. +
[3] The result type for the operator->() depends on the category and value type of the iterator and is somewhat complicated to describe. But be assured, it works in a stardard conforming @@ -681,6 +728,7 @@ bool operator==(const iterator_adaptor<B1,P,V1,R1,P1,C,D>&, -->