Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2004-01-24 06:29:36


> The documentation says: "If types T1 and T2 are the same type, then
> there is only one version of the single-argument constructor, and this
> constructor initialises both values in the pair to the passed value."
>
> There is no indication that only one object of type T1 will actually
> ever be created when T1 == T2 and are empty, even though that is in
> fact the case. This violates a reasonable expectation (given by the
> standard) that two objects of the same type will have distinct
> addresses. The difference *is* detectable by the user.

This occurs in other situations as well; in fact it's an intrinsic part of
compressed_pair that the addresses returned by first() and second() may be
the same if *either* T1 or T2 are empty classes, that's the whole point of
the object.

The reason for doing things that way was that most compilers do not enable
the empty base optimisation when multiply inheriting (and we can't inherit
from the same class twice), however this does have the side effect that the
constructor and destructor for that type are called only once and not twice,
off hand I can't think of any situation where this would actually cause a
problem in practice. This could be "fixed" (and probably should be) by
making one object instance a base class, and the other a data member, but
they will still have the same address.

John.


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