Boost logo

Boost :

Subject: Re: [boost] Interest in a "Heterogenous Container" system?
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-07-31 09:58:29

[It looks like I forgot to send this message.]

Christian Schladetsch wrote:
> On Tue, Jun 30, 2009 at 11:14 AM, Simonson, Lucanus J <
> lucanus.j.simonson_at_[hidden]> wrote:
> > [snip] Deriving from a common ancestor base class is contrary
> > to generic programming. Knowing all your types ahead of time
> > (at compile time) is not unreasonable, it is the common case
> > for generic programming.
> Sure, but as much as we'd perhaps like to forget about it, it
> is true that C++ supports OO style as well as generic
> programming, especially in GUIs and other object hierarchies.
> In these cases, you either cannot know or don't want to know
> all the types that may be used ahead of time. This is the
> basic premise of loose coupling.

ptr_containers and the heterogeneous containers should account for polymorphic type use cases. Somewhere in that space, however, should be support for cases of homogenous containers of pointers to a single type such that the purpose of the container, aside from holding the pointers, is to assume ownership of them and delete them when the container goes out of scope (unless told to avoid taking ownership).

The latter use case makes tracking the lifetime of allocated memory easier. Yes, containers of shared_ptrs would work, but they add overhead that isn't always wanted. Yes, it is possible to leave pointers to former elements dangling when the container is destroyed, but C++ is replete with such opportunities to cause problems. Sometimes, performance wins.

The heterogeneous containers, being implemented as class templates, need only be defined in terms of operations supported by its parameterizing types. Require that the type T be a common base of all objects in the container and that it provide specific polymorphic operations and you have all that's needed. There's no need to impose that by requiring derivation from any particular base class, just whatever is sensible to the user. If that can be captured via TMP to support types that aren't related with a default that assumes types that are, all the better.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Boost list run by bdawes at, gregod at, cpdaniel at, john at