Syntactic Sugar for Construction of Empty Dynamic Arrays of a Given Type

"Nordlöw" per.nordlow at gmail.com
Sun Mar 23 10:55:21 PDT 2014


On Sunday, 23 March 2014 at 14:58:53 UTC, bearophile wrote:
> Nordlöw:
>
>> Is there a convenicene function for assigning an empty dynamic 
>> array of a given type to a variable?
>>
>>    cast(int[])[];
>
>>                    _range = cast(D[])[];
>
> If the variable is already typed, you can use [] otherwise you 
> can use cast(T)[]  or (T[]).init to avoid casts.
>
> Bye,
> bearophile

Ok. Enough for now...but Is there a way to avoid this array 
special handling:

                 static if (isArray!R)
                     _range = (D[]).init;
                 else
                     _range = R(); // return empty range

through some initializer expression for _range that covers both

     R()

and

     (D[]).init

?


More information about the Digitalmars-d-learn mailing list