|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-03-08 14:41:08
From: "Howard Hinnant" <hinnant_at_[hidden]>
> On Friday, March 8, 2002, at 12:51 PM, Peter Dimov wrote:
>
> > 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.
>
> I'm not following completely how this would solve the numerics problem
> that zero initializing the vector is too expensive, and also solve your
> v.insert problem.
I may be misunderstanding the nature of the "numerics problem."
As I see it, _someone_ has to initialize the vector. The problem is when we
have a library function that will initialize an array of doubles.
Constructing a vector inits to zero, then that library function inits to the
right values, hence the double init problem.
Passing the function to the vector constructor solves the problem - and
leaves the vector initialized so that its other methods work after
construction, as is the case now.
Is there another instance of the "expensive init" problem that I'm missing?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk