|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-03-08 12:51:11
From: "Howard Hinnant" <hinnant_at_[hidden]>
> On Friday, March 8, 2002, at 12:29 PM, Peter Dimov wrote:
>
> > From: "Howard Hinnant" <hinnant_at_[hidden]>
> >> 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. :-)
>
> Does passing the vector a chunk of uninitialized memory solve this
> problem?
No. One way to solve it (that I see) is
template<class F> vector::vector(size_type n, F f);
that will allocate memory and use f(this->_Ptr, n) to initialize it.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk