Boost logo

Boost :

From: rwgk (rwgk_at_[hidden])
Date: 2002-02-28 00:00:25

--- In boost_at_y..., Damien Fisher <damien_at_m...> wrote:
> > Why not? If you write vector<complex<double> > vec(10);
you have made
> > a conscious decision to create a vector that started with 10
> > numbers. Its not unreasonable for a user to use one of those
> > numbers. If you just wanted to reserve space for 10 complex
numbers you
> > could have just used the default constructor then called reserve
> > Besides, the default constructor is inline, so how slow could it
> >
> > Joe Gottman
> 100 x 100 matrix of complex numbers => 100 * 100 * 2 unnecessary
> initializations. and that's not even a particularly large example.

I also find this to be a performance problem.

std::complex<T>() should do nothing if T has a trivial
destructor (otherwise initialization is a necessity). The
distinction requires type traits, which are unfortunately
not (yet?) part of the standard.

Unfortunately the reserve() solution eventually requires
use of push_back(), which is also slow.

This brings us to the next item on the wish list:

struct no_initialization_flag {};

vector(const size_type& sz, no_initialization_flag) : ...


Boost list run by bdawes at, gregod at, cpdaniel at, john at