Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-09-09 11:19:08

Joao Abecasis <jpabecasis_at_[hidden]> writes:

> David Abrahams wrote:
> > I think the question is whether it's ever desirable to break the
> > current C++ invariant that no two objects of the same type will ever
> > share an address **in generic code** -- that is, when you don't know
> > anything about the assumptions that may be made by that type.
> An alternative implementation is to privately inherit from the
> specified type for empty classes as compressed_pair does. This
> maintains the invariant but has the drawback that inheritance is
> visible in user code.

Yeah, the primary danger being unintentional overriding of virtual
functions from the private base. I like the protection your idea
provides. You could arrange a compressed_pair based on this design
that still maintains the invariant. And then you could make it smart
enough to aggregate other compressed_pairs without ever allocating
two of the same type at the same address.

> For a generic compressed_tuple the private inheritance should not be
> a problem.

I'm not sure what you mean by that, sorry.

Dave Abrahams
Boost Consulting

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