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
> >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
> >
> >
> I added a test case to operations_test.cpp, and it failed miserably at
> 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.


           David Abrahams * Boost Consulting
dave_at_[hidden] *

Boost list run by bdawes at, gregod at, cpdaniel at, john at