Boost logo

Boost Users :

From: David Abrahams (yg-boost-users_at_[hidden])
Date: 2002-07-26 09:22:41


"Hickman, Greg" <greg.hickman_at_[hidden]> wrote in message
news:58F604E3D17AD4119D8600508BE32506017B6CF2_at_emss07m04.lmtas.lmco.com...

> I'm brand new to iterator_adaptors, and this is probably way too trivial
an
> example, but I have several classes in my project which aggregate other
> polymorphic objects in part-whole relationships. I'd like clients who
call
> 'the_aggregate.begin()' to be able to call non-const methods on the
> aggregate's Parts, but I'd like to prevent direct replacement of the
> underlying container element 'Part*' itself. Likewise, I'd like clients
who
> call 'the_aggregate.begin() const' to be prevented from doing anything
with
> the aggregate's Parts other than calling it's const methods. Of course,
the
> STL container-supplied iterators aren't intended to work in this way.
>
> If this situation is common enough, and iterator_adaptor can be used to
> quickly generate iterators with the desired behavior (I haven't completely
> tested it as of yet, but it seems to work), then perhaps this is just one
> example of a reasonable "Hello, world" introduction to iterator_adaptors.

I think the indirect iterator adaptor does what you want out-of-the-box.
Unfortunately, I don't think its implemntation is any simpler than the
transform iterator example which is already in the docs and which Beman had
trouble with as a way of getting started.

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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net