Boost logo

Boost :

From: rwgk (rwgk_at_[hidden])
Date: 2002-03-08 14:06:30


--- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> From: "Howard Hinnant" <hinnant_at_t...>
> > Meanwhile vector<double> v(10, uninitialized_flag) breaks no
vector
> > invariants. The vector is destructible. The vector elements can
be
> > assigned into. If your hardware doesn't mind (mine doesn't), you
can
> > even assign from this uninitialized vector. I can't think of a
reason
> > why you would want to do that though.
>
> You can't v.insert(v.begin(), 5.0) because copying the
uninitialized doubles
> is undefined behavior. The insert() preconditions do not say that
you can't.
> Something is wrong. :-)

In my mind

vector<double> vec(100000, uninitialized_flag());

means these things:

1. I do not want to waste time for something that I am
absolutely sure I do not need (the default construction)
because

2. I am about to fill the memory with the given number
of elements by some other facility, and

3. I am taking responsibility and I have read the
documentation for uninitialized_flag() which told me
to initialize the memory before doing /anything/ else
with it.

Being safe by default is great, but IMO forcing everyone to
waste time only to be safe under any conceivable eventuality
is misguided and may be one of the reasons why C++ still has
a bad reputation among many (non-computer) scientists.

Ralf


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