Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-07-26 13:36:55


From: "Beman Dawes" <bdawes_at_[hidden]>

> 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.

I already am; the default policies are taking care of equality testing, as
indicated by my comment. Supplying operator++ for an slist_node wouldn't
help at all since the Base type is slist_node*, and its operator++ is
already defined on pointers (to do the wrong thing for this iterator).

> Another thing that still confuses me is why you need to specify Value,
but
> can let Reference, Pointer, and Distance default.

It's all spelled out in the table. The default value_type is
iterator_traits<slist_node*>::value_type == slist_node, not slist_data.

> 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.

Maybe I'm just too close to the library. I can't imagine anything to say
which isn't obvious, and thus obfuscating. Could you take a stab at writing
the accompanying narrative?

-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave_at_[hidden] * http://www.boost-consulting.com

> >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;
>
>
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk