Empty array and AA literals

bearophile bearophileHUGS at lycos.com
Sun Apr 6 02:41:08 PDT 2014


dnspies:

> What about if I have a 2D array (ie int[][]) and I want to 
> append an empty int[] on the end?  Will this work?
>
> int[][] nested;
>
> nested ~= null;
>
> ~ is overloaded, so how does it know what type I intend null to 
> be?  How can I specify it?

You can increase by one of the length of the outer array, or you 
can append an empty one:

nested.length++;

or:

nested ~= [];

I don't remember if you can also append a null. Appending a null, 
if it works, could be more efficient. Take a look at the ASM.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list