Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-09-15 17:39:15


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

> At 05:13 PM 9/14/2002, David Abrahams wrote:
>
> >> 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.
>
> I think you should point that out in the documentation. I just skimmed
the
> docs again and there is no indication I could see that it isn't safe to
> derive from iterator_adaptor.

Ah, but it *is* safe!
It's just that the result will probably not be an iterator ;-)
OK, since you're the 2nd person to have made that mistake this week, I'll
add a note.

> Instead the docs say things like "There is an unlimited number of ways
the
> iterator_adaptors class can be used to create iterators" which made me
> think iterator_adaptor performed some magic that made derivation safe.

Hmm, I don't think that conclusion was warranted. There are an unlimited
number of valid ways to use int, but that doesn't make it safe to test an
unininitialized one.

> Since, as Thomas Witt points out, the point of derivation was to add a
> constructor, it would be nice if the docs explained what a user is
supposed
> to do when faced with this need.

I'm not sure it's worth it, since Jeremy and I are gonna design a new
iterator_adaptor next month.

> > 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.
>
> I can't find any "formula" in the docs for simple iterators that require
> constructors.

I'm a little confused by that. All the iterators have constructors.
I suppose you mean constructors other than those specified by
iterator_adaptor itself?
There really isn't any such formula, since you can't make such an iterator
with iterator_adaptor as it currently stands.
However, you can make an object generator function just like all the
adaptors in the library have.

> The only discussion I found of generators said "The nicest way to package
> the construction of the transform iterator is to create a type
generator".
> That seems to imply there are other choices, and that using a generator
was
> optional.

True, there are. It doesn't mean you can choose anything arbitrarily,
however.
Anyway, an object generator is the easiest way to do it in the current
design.

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