memoize -- AAs don't work for ubyte[4] keys

Tomek Sowiński just at ask.me
Tue Jan 4 15:47:29 PST 2011


Andrei Alexandrescu napisał:

> BTW I think the rgb2cmyk implementation in Higher Order Perl (which I 
> copied) is a bit convoluted. A simplified version is:
> 
> ubyte[4] rgb2cmyk(ubyte[3] rgb)
> {
>      immutable m = max(rgb[0], rgb[1], rgb[2]);
>      return [ cast(ubyte)(m - rgb[0]), cast(ubyte)(m - rgb[1]),
>              cast(ubyte)(m - rgb[2]), ~m ];
> }
> 
> Two nice typing touches: max does not necessitate a cast because it's 
> implemented to return ubyte for ubytes, and ~m also doesn't need a cast 
> thanks to value range propagation.
> 
> I don't know how to get rid of the remaining casts.

I didn't know you have to put them:)

http://www.digitalmars.com/d/2.0/expression.html#ArrayLiteral

"The type of the first element is taken to be the type of all the elements, and all elements are implicitly converted to that type."

But now (2.051) I tested and it seems it goes for the common type. No mention on the change log... Was that changed? If so, why?

-- 
Tomek



More information about the Digitalmars-d mailing list