Boost logo

Boost :

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

Mathias Gaunard wrote:
> Stewart, Robert wrote
> >>
> >>> Yes, containers of shared_ptrs would work, but they add
> >>> overhead that isn't always wanted.
> >> Then use containers of unique_ptr, like you should (shared_ptr
> >
> > "like you should" is a rather strong statement.
> If you want a container of pointers with the container owning
> the pointees, in order to use inclusion polymorphism for
> example, then a container of unique_ptr is the standard
> solution, while a container of shared_ptr is not only overkill
> since it adds a lot of useless overhead, it also gives the
> wrong semantics.
> A container of clone_ptr is a more elegant solution if you
> can't use move semantics, since it actually has the right
> ones. You may want to implement it using COW however since non
> move-aware containers can do a lot of spurious copies.

It seems you just made my point for me. There are numerous approaches to take, each with tradeoffs.

> > All of those schemes mean that the container interface is in
> > terms of those wrapper types rather than raw pointers. They
> > will work, but they complicate the code using the elements.
> > I'm not suggesting that is onerous, but the interface isn't
> > as simple.
> How are smart pointers, smart references or smart objects
> (whatever you want to call them) any more difficult to use than
> pointers or objects?

The client code must be written in terms of wrapper_type<T> or container::value_type rather than T * or it must ask the wrapper for its raw pointer, an extra step. The point I'm making is that there are times when a container that does nothing more than own pointers is useful. Other code can use the pointers at will until the container goes out of scope. There's no need to wrap the pointers in anything in that case. Maybe that's too uncommon to warrant support in this context, but that's the use case I was proposing.

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