Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-09-14 16:13:50


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

> At 08:33 AM 9/14/2002, Thomas Witt wrote:
> >On Friday 13 September 2002 19:49, Beman Dawes wrote:
> >> * The directory_iterator implementation now uses
> >boost::iterator_adaptor<>.
> >
> >IIUC directory_iterator is derived from iterator_adaptor and
reimplements
>
> >operator-> as a compiler workaround.
> >
> >Are you sure the following works (i.e. does not need the workaround)
> >
> >(++directory_iterator(valid_directory_path))->file_path(); ?
> >
> >See posting
> >
> >http://aspn.activestate.com/ASPN/Mail/Message/boost/1356436
>
> I added a test case to operations_test.cpp, and it failed miserably at
run
> time (protection fault) for all compilers except Borland:-( Incrementing
> the iterator first in a separate expression, then using ->, worked
> correctly.
>
> I frankly don't understand the details of this problem. Am I using
> iterator_adaptor incorrectly

Yes. A class derived from a valid iterator is not a valid iterator unless
you add all the appropriate operators. That's why iterator_adaptor<>
defines all the operators. Instantiations of iterator_adaptor<> are valid
iterators. Derived classes are generally not valid iterators. That's why
all the examples in the library use type generators instead of inheritance.
Just follow the formula given by the library docs and you'll be fine.

-Dave

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


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