Port of Python's difflib.SequenceMatcher class
Oskar Linde
oskar.lindeREM at OVEgmail.com
Thu Dec 7 04:34:06 PST 2006
Bill Baxter wrote:
> V get(V,K)(V[K] dict, K key, V def = V.init)
> {
> V* ptr = key in dict;
> return ptr? *ptr: def;
> }
>
[snip]
> char[][int] i2s;
> i2s[1] = "Hello";
> i2s[5] = "There";
>
> writefln( i2s.get(1, "yeh") );
> writefln( i2s.get(2, "default") );
> writefln( i2s.get(1) );
> writefln( i2s.get(2) );
>
> Too bad the template version doesn't work.
> D doesn't seem to be able to pick out the V and K from an associative
> array argument.
Sorry, i missed this part. The compiler is confused by not being able to
tell if V should be char[] or char[3].
writefln( i2s.get(1, "yeh"[]) );
writefln( i2s.get(2, "default"[]) );
both works. So you are right. The IFTI could perhaps be improved by
figuring out that both V argument types are implicitly convertible to
the same type.
/Oskar
More information about the Digitalmars-d-announce
mailing list