On 11/6/10 12:13 AM, Rainer Deyke wrote:
On 11/5/2010 17:41, Walter Bright wrote:
In other words, I create an array that I mean to fill in later, because
I don't have meaningful data for it in advance.

That's a faulty idiom.  A data structure that exists but contains no
valid data is a bug waiting to happen - no, it /is/ a bug, even if it
does not yet manifest as incorrect observable behavior.  (Or at best,
it's an unsafe optimization technique that should be wrapped up in an
encapsulating function.)

To find an array that always has initialized data, look no further than std::vector. There is no way to grow an std::vector without filling it with data under user's control. The only place where std::vector assumes a default is the resize function:

void vector<T>::resize(size_type newSize, T filler = T());

If that default went away, the user would always be required to provide a filler when growing the vector.


Andrei

Reply via email to