Boost logo

Boost :

From: Ed Brey (edbrey_at_[hidden])
Date: 2001-08-20 12:00:15


From: "Vesa Karvonen" <vesa.karvonen_at_[hidden]>
> From: "Ed Brey" <edbrey_at_[hidden]>
> [...]
> > The question is: how should one program algorithms that need deferred
> > initialization of elements? If vector is to be the end all and do all
> > dynamic array type, replacing VLAs et al., it needs to answer this
> > question.
> [...]
>
> Standard vector does support a form of deferred initialization: you are
> allowed to reserve space for elements that can be initialized later by using
> vector methods such as assign, push_back, etc...

Yes. However, this covers only one special case of the general problem. In the general problem, consider that you have 10 objects have an inherent order, and you want them placed in contiguous space in memory. The order in which you obtain the information needed to construct each object is unspecified, so you may first construct v[8], then v[1], and so on. The combination of reserve() and push_back() is helpful only when the order is v[0], v[1], etc. Assign() is useful only when all the data for the vector is available at once.


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