Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-12-07 15:09:27


Robert Ramey <ramey_at_[hidden]> writes:

> I am working on a problem for which the most natural
> solution is to derive from the boost::transform_iterator.

Deriving from a working iterator type is almost never the most natural
solution to anything, because usually the resulting type will not be
an iterator since its operator++ will have the wrong return type.

> Unfortunately, it does not seem possible to do this.
>
> The transform iterator does not include a derived
> class in its list of parameters as it would need in
> order to invoke most derived functions.
>
> Is there any reason why the design prohibits
> derivation?

It doesn't prohibit it; it just doesn't encourage it.

Probably the best reason is that it wasn't an important use case, and
making it easy to build derived iterators would make
transform_iterator harder to use.

> Does anyone have any suggestion on how to get the same effect?

Not sure what effect you want. Can you describe the iterator you're
trying to build?

> I believe that this observation applies to all the other specialized
> adaptors as well.

I'm not convinced it's a design problem yet.

-- 
Dave Abrahams
Boost Consulting
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