Boost logo

Boost Users :

From: Beman Dawes (bdawes_at_[hidden])
Date: 2002-07-26 13:24:20


At 11:10 AM 7/26/2002, David Abrahams wrote:

>OK, here's my (untested) singly-linked-list iterator:

Yes! Nice! Having this would have saved me a lot of bumbling around.

How about supplying slist_node with an operator++ (and eliminating
slist_policies::increment), so that you are illustrating the two different
possibilities for supplying a required operation. That was something that
confused me initially.

Another thing that still confuses me is why you need to specify Value, but
can let Reference, Pointer, and Distance default. A little cometary in the
docs which go with the example to explain the rationale for your choice of
template parameter values would be much appreciated.

--Beman

>typedef std::string slist_data;
>struct slist_node
>{
> slist_node* next;
> slist_data data;
>};
>
>struct slist_policies : default_iterator_policies
>{
> template <class IteratorAdaptor>
> void increment(IteratorAdaptor& x) {
> x.base() = x.base()->next;
> }
>
> template <class IteratorAdaptor>
> typename IteratorAdaptor::reference dereference(IteratorAdaptor& x) {
> return x.base()->data;
> }
>
> // initialize, equal covered by default policies
>};
>
>typedef iterator_adaptor<slist_node*, slist_policies, slist_data,
>category_is<std::forward_iterator_tag> > slist_iterator;
>
>typedef iterator_adaptor<slist_node const*, slist_policies, slist_data
>const, category_is<std::forward_iterator_tag> > slist_const_iterator;


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net