Boost logo

Boost :

From: Yitzhak Sapir (yitzhak.sapir_at_[hidden])
Date: 2004-02-26 11:48:15


> -----Original Message-----
> From: christian.engstrom_at_[hidden]
> [mailto:christian.engstrom_at_[hidden]]
> Sent: Thursday, February 26, 2004 4:40 PM
> To: boost_at_[hidden]
> Subject: [boost] Proxy indirect container adaptor: 4 claims
>
> --Is there a way to define a package for indirect containers, so that
> one can take a program that uses a direct container, and
> convert it to
> using an indirect container just by changing the definition of the
> container type?

You could define a container adaptor that takes a container, and modifies the begin()/end() iterators to return indirect iterators to the original begin()/end(). Then instead of:
  typedef some_container container_type;
you would have:
  typedef adaptor<some_container> container_type;

> --Would it be any useful to be able to switch containers like that?
>
> The problem here is of course that "usefulness" is very much
> in the eye
> of the beholder, so all that I can say with certainty is that I
> personally would find it quite useful, and that I don't see why other
> people as well shouldn't sometimes find themselves in situations when
> they would want to change container types easily. After all,
> isn't one
> of the great benefits of the STL containers that they have
> (reasonably)
> uniform interfaces, so that it's easy to switch between the different
> container types, often by just changing a typedef?

You might want to read "Beware the Illusion of container-independent code", by Scott Meyers in his book: http://www.awprofessional.com/isapi/content/images/0201749629/items/item2-2.pdf
The full book is at: http://www.awprofessional.com/catalog/product.asp?product_id={AA4735AF-4407-4011-B7D3-0C924DFA675D%7d


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk