[:] as empty associative array literal, plus warning for null
Timon Gehr
timon.gehr at gmx.ch
Wed Jul 3 13:03:30 PDT 2013
On 07/03/2013 08:10 PM, bearophile wrote:
> ...
>
> This means you have to keep "null" in the language to represent an empty
> associative array, because someone somewhere will surely want a literal
> that avoids memory allocations. So lot of people will keep using null,
> and the coding situation is improved about zero.
> ...
It would be improved.
Excerpt from my code:
private static Variant[VarDecl] parseContext(void[] mem,FunctionDef fd){
// ...
Variant[VarDecl] r;
// (stupid built-in AAs)
assert(fd !is null);
r[cast(VarDecl)cast(void*)fd]=Variant(null);
r.remove(cast(VarDecl)cast(void*)fd);
// ...
}
That code using an allocating [:] literal:
private static Variant[VarDecl] parseContext(void[] mem, FunctionDef fd){
// ...
Variant[VarDecl] r = [:];
// ...
}
Is there currently a better way to initialize AAs?
More information about the Digitalmars-d
mailing list