Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2005-05-28 05:07:27


> 1. Zero initialization is better than uninitialized because it is safer.
> 2. Uninitialized is better because it is much faster, especially if you
> have containers of such elements. You can always explicitly initialize if
> you want.

As I remember when compressed_pair came up for the informal reviews we had
back then, there was a feeling that std::pair was over specified, and that
POD types should not be zero-initialised.

There is one more argument in favour that I would add:

If POD types are uninitialised then const-POD types *have* to be explicitly
initialised in the compressed_pair constructor. IMO this is a good thing:
it seems unlikely to me that zero initialisation is really what you want if
the type is const, so we're catching a potential source of error early.

The down side as already pointed out is that this is different from
std::pair, it may also break generic code if POD's and non-POD's behave
differently (although arguably we're really just exposing bugs in program
logic).

Whichever road we take it should be clearly documented, at the very least,
I'll update the docs for this release, to reflect current behaviour.

John.


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