adding properties/methods to AA's?
Oskar Linde
oskar.lindeREM at OVEgmail.com
Tue Jul 24 04:57:41 PDT 2007
Bill Baxter wrote:
> Oskar Linde wrote:
>> just write the function as ubyte[] serialize(Variant[char[]] input)
>> and call it as:
>>
>> map.serialize(); // Note, the trailing pair of empty parentheses
>
> Hey you're right! I forgot that AA's work that way too. I had this
> little test function in my tests directory that didn't work at some
> point but now apparently it does:
>
> V get(V,K)(V[K] dict, K key, V def = V.init)
> {
> V* ptr = key in dict;
> return ptr? *ptr: def;
> }
>
>
> void main()
> {
> char[][int] i2s;
> i2s[1] = "Hello";
> i2s[5] = "There";
>
> writefln( i2s.get(1, "yeh") );
> writefln( i2s.get(2, "default") );
> writefln( i2s.get(1) );
> }
>
> Boffo!
It has worked since DMD 0.178. Walter even refers to your post with this
same example in the changelog. :) (The reason the above didn't work
earlier was issues with IFTI and converting char[n] -> char[])
--
Oskar
More information about the Digitalmars-d-learn
mailing list