On 11/14/2012 7:20 PM, Dmitry Olshansky wrote:
11/14/2012 9:44 PM, Andrei Alexandrescu пишет:
This is new! What does this mean?
I'm sure it is nothing new. Basically AA is a reference type but it is
auto-magically created on the first insertion. This is called magic null
behavior.
void foo(int[int] aa){
//aa here is null
aa[1] = 1;
//now the local aa points to a new hash-map
}
void main(){
int[int] map;
foo(map);
//map in this scope is still null
assert(1 in map); // fails
}
I'm in favor of implicitly allocating an AA on definition that'll make
it a proper reference type.
I don't like the "magic null behaviour", but I see issues with this
straight forward implementation: how can you define a statically
initialized struct value (including init) that contains an associative
array? It will have to run a default constructor to allocate the AA root
object, introducing something like the often rejected user-defined
default constructor for structs.