Boost logo

Boost :

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


From: "Jeremy Siek" <jsiek_at_[hidden]>

> Looks great! BTW, I think this example will be really useful to people
who
> are trying to use old C data-structures inside of new C++ code.
>

Thanks! Now where's that line_iterator?

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

> dave> OK, here's my (untested) singly-linked-list iterator:
> dave>
> dave> typedef std::string slist_data;
> dave> struct slist_node
> dave> {
> dave> slist_node* next;
> dave> slist_data data;
> dave> };
> dave>
> dave> struct slist_policies : default_iterator_policies
> dave> {
> dave> template <class IteratorAdaptor>
> dave> void increment(IteratorAdaptor& x) {
> dave> x.base() = x.base()->next;
> dave> }
> dave>
> dave> template <class IteratorAdaptor>
> dave> typename IteratorAdaptor::reference
dereference(IteratorAdaptor& x) {
> dave> return x.base()->data;
> dave> }
> dave>
> dave> // initialize, equal covered by default policies
> dave> };
> dave>
> dave> typedef iterator_adaptor<slist_node*, slist_policies, slist_data,
> dave> category_is<std::forward_iterator_tag> > slist_iterator;
> dave>
> dave> typedef iterator_adaptor<slist_node const*, slist_policies,
slist_data
> dave> const, category_is<std::forward_iterator_tag> >
slist_const_iterator;
> dave>
> dave>
> dave> -Dave
> dave>
> dave>
> dave> -----------------------------------------------------------
> dave> David Abrahams * Boost Consulting
> dave> dave_at_[hidden] * http://www.boost-consulting.com
> dave>
> dave>
> dave> ----- Original Message -----
> dave> From: "Jeremy Siek" <jsiek_at_[hidden]>
> dave> To: <Boost-Users_at_[hidden]>
> dave> Cc: <boost_at_[hidden]>
> dave> Sent: Friday, July 26, 2002 10:58 AM
> dave> Subject: Re: [Boost-Users] Re: [boost] Iterator Adaptor Poll
> dave>
> dave>
> dave> > On Fri, 26 Jul 2002, David Abrahams wrote:
> dave> > dave>
> dave> > dave> Don't you think people will find an iterator which
traverses the
> dave> > dave> elements of a real sequence to be more-obvious? That's why
I'm
> dave> > dave> suggesting the singly-linked list iterator.
> dave> >
> dave> > The singly-linked list example was the second thing that popped
into my
> dave> > mind... I like that a lot too. Perhaps we should do both :)
> dave> >
> dave> > Cheers,
> dave> > Jeremy
> dave> >


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