|
Boost : |
From: Herve Bronnimann (hbr_at_[hidden])
Date: 2002-10-17 13:31:26
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.
Granted you can't pass a range as a single object, but Jeremy Siek has
written (in the boost-sandbox) a series of container algorithms that
take a pair<iterator,iterator> (representing a range) and applying
standard library functions to the pair. It's pretty usable (he uses it
in the BGL IIRC, but don't take my word for it, go look!)
For instance: begin(Vector&) or begin(pair<iter,iter>&) will give you
the beginning of the range. Enables you to write generic algorithms.
I'm really unclear as to what a container adaptor library would provide
(are you thinking of something along the lines of std::stack,
std::queue, and std::priority_queue?) I'm pretty convinced that
fixed-size vectors would encourage using the wrong solution style, but
they are a convenience, and some people can't live without a certain
level of it. Other adaptors may be more useful, would you have a few
suggestions?
> Is there something currently in Boost that will allow me to do
> these sorts of things? If not, is this something the Boost
> community would be interested in?
Check out:
boost-sandbox/boost/sequence_algo/container_algo.hpp
-- Herve'
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk