|
Boost : |
From: Martin Weiser (weiser_at_[hidden])
Date: 2002-10-18 06:40:20
On Donnerstag, 17. Oktober 2002 20:31, Herve Bronnimann wrote:
> On Thu, Oct 17, 2002 at 02:08:59PM -0400, David A. Greene wrote:
> > I've often found the need to construct container adaptors to provide
> > things such as a fixed-size vector. After once again writing
> > some of these things, I'm wondering whether it might be worth
> > designing a container adaptor library similar to the iterator
> > adaptor library. I can see a container traits library coming
> > out of this as well.
>
> David:
>
> I assume that by fixed-size vectors your mean a sequence container
> where all the operations insert/erase have been made inacessible?
> imho you don't need a container adaptor for fixed-size vector. You
> should rewrite your code to use a range [first,last) instead.
Although small to medium size algorithmic blocks are best expressed in
terms of ranges, there are several situations where this is inconvenient.
If you store the range somewhere and the container is modified, your
range may be invalidated. A container adaptor maintaining a reference to
the actual container is still valid. Sometimes a container interface is
slightly easier to use. Sometimes it is more efficient (think of size()
vs distance(first,last) for non-random-access-iterators). Then there is
the ownership issue. Container adaptors can easily incorporate the
container they adapt, or share the container with reference counting, or
leave it unmanaged - selectable behaviour via policies. This would be
hard to accomplish by iterators.
As always, the old truth holds: all you can achieve with container
adaptors can also be achieved without them - but maybe more cumbersome.
Yours,
Martin
-- Dr. Martin Weiser Zuse Institute Berlin weiser_at_[hidden] Scientific Computing http://www.zib.de/weiser Numerical Analysis and Modelling
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk