Initializing assoc array to non-null
d coder
dlang.coder at gmail.com
Sat Jun 1 07:51:42 PDT 2013
Greetings
Is there a way to initialize an associative array to a non-null (but still
empty) state? The only way I know is by adding an element and then removing
it. Did I miss something obvious? Basically I want to write lines 7-8 in
the following code in a cleaner fashion. Any ideas?
Regards
- Puneet
class Foo { // 1
string[int] _aa; // 2
public string[int] aa() { // 3
return _aa; // 4
} // 5
this() { // 6
_aa[0] = ""; // 7
_aa.remove(0); // 8
} // 9
} // 10
void main() { // 11
Foo foo = new Foo; // 12
string[int] bb = foo.aa; // 13
assert(bb !is null); // 14
bb[0] = "zero"; // 15
assert(bb is foo.aa); // 16
} // 17
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130601/c10b07b6/attachment.html>
More information about the Digitalmars-d-learn
mailing list