Steven Schveighoffer <> changed:

           What    |Removed                     |Added
                 CC|                            |

--- Comment #1 from Steven Schveighoffer <> 2011-02-17 
04:30:23 PST ---
This does not need to be a language thing, library could suffice:

auto a = createArray!(int[][])(5, 5, 1); // initialize 5x5 array with the value
1 in each cell.

auto a = createUninitArray!(int[][])(5, 5); // name needs work...

In which we can hide your shown implementation (this can be factored out a

BTW, your code does not work properly for array appending.  It does not
initialize the hidden "allocated length" field, which would likely result in
reallocation on append.

Some other functions probably needed:

a.extendUninit(size_t newlength);

which is like a.length = newlength but does not initialize the new area.


I agree a syntax change would be more in line with current array allocation
operations (which are currently all syntax based), but I don't really like your
proposed syntax.

I would propose if we wanted to do a syntax change to do:

auto a = new int[][](5, 5, 1);
auto a = new int[][](5, 5, void);

Where the optional final argument determines the initial value.

This fits perfectly with the current array creation syntax:

new T(dim1, dim2, ..., dimN)

where T is a N dimensional array.  We can just add an extra parameter for the


One problem with this whole proposal is the issue with struct semantics.  That
is, let's say a struct has a postblit, and you wanted to create an array of
those structs with a default value.  Should the runtime call the postblit for
each element?

I'd say it should.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to