Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2002-07-26 10:10:24


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

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;

-Dave

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

----- Original Message -----
From: "Jeremy Siek" <jsiek_at_[hidden]>
To: <Boost-Users_at_[hidden]>
Cc: <boost_at_[hidden]>
Sent: Friday, July 26, 2002 10:58 AM
Subject: Re: [Boost-Users] Re: [boost] Iterator Adaptor Poll

> On Fri, 26 Jul 2002, David Abrahams wrote:
> dave>
> dave> Don't you think people will find an iterator which traverses the
> dave> elements of a real sequence to be more-obvious? That's why I'm
> dave> suggesting the singly-linked list iterator.
>
> The singly-linked list example was the second thing that popped into my
> mind... I like that a lot too. Perhaps we should do both :)
>
> Cheers,
> Jeremy
>
>
> ----------------------------------------------------------------------
> Jeremy Siek http://php.indiana.edu/~jsiek/
> Ph.D. Student, Indiana Univ. B'ton email: jsiek_at_[hidden]
> C++ Booster (http://www.boost.org) office phone: (812) 855-3608
> ----------------------------------------------------------------------
>
>
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost


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