Better AAs
bearophile via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jul 6 15:53:53 PDT 2014
Recently some people have said that D has about two thousand bugs
open, so there is no hope to fix them, etc. But not all bugs are
equally important. Probably less than about one hundred of those
bugs are significantly important, so if you manage to fix those,
D becomes something different (some of those bugs are enhancement
requests).
Lately a bug that has plagued D has apparently being fixed, now D
is a bit more adult language.
This code:
import std.stdio, std.typecons;
struct Foo { string s; }
alias Bar = Tuple!string;
auto s1 = "he";
auto s2 = "llo";
void main() {
int[Foo] aa1;
aa1[Foo("hello")] = 1;
aa1[Foo(s1 ~ s2)] = 2;
aa1.writeln;
int[Bar] aa2;
aa2[Bar("hello")] = 1;
aa2[Bar(s1 ~ s2)] = 2;
aa2.writeln;
}
Now compiles and outputs something right:
[Foo("hello"):2]
[Tuple!string("hello"):2]
More problems are left in the D AAs, but now you can actually
start using D associative arrays in your code.
Rust has not done the significant D design mistake of putting the
associative arrays inside the language/runtime, but D AAs are
getting better.
Bye,
bearophile
More information about the Digitalmars-d
mailing list