What is the current point to empty/null associative arrays?
Cooler
kulkin at hotbox.ru
Fri Nov 29 00:32:11 PST 2013
First - I search the forum for discussion on my question, but all
talks ends with nothing.
Therefore again:
import std.stdio;
void fillArray(string[int] a){ a[10] = "A"; }
void main(){
string[int] b;
fillArray(b); // Here we expect b gets new element [10:"A"],
but...
writeln(b); // Prints [] (empty array)
b[1] = "B";
fillArray(b);
writeln(b); // Prints [1:"B", 10:"A"] (OK, expected behaviour)
}
In the first call fillArray() gets null AA and creates new one
inside { a[10] = "A"; }, that will not be returned. After the
call array b remains null.
In the second call fillArray() gets not-null AA and successfully
add new element to it.
The problem can be solved if we have empty associative array
initializer (aka string[int] b = [:]), as already discussed on
this forum. Does any body knows what is the current situation
with such initializers? Or may be described problem can be solved
by other means?
More information about the Digitalmars-d
mailing list