Port of Python's difflib.SequenceMatcher class
Bill Baxter
dnewsgroup at billbaxter.com
Thu Dec 7 17:09:58 PST 2006
Oskar Linde wrote:
> 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
Oh, ok. So I was right, but for the wrong reason. :-) The compiler
message wasn't very specific about what it didn't like, just "no match"
was all it was willing to divulge.
These char[] char[N] conversion issues are rather annoying.
--bb
More information about the Digitalmars-d-announce
mailing list