Cool thing about D, number #72

Bill Baxter dnewsgroup at billbaxter.com
Tue Apr 24 06:01:19 PDT 2007


Daniel Keep wrote:
> 
> I discovered the same thing, by roughly the same thinking.  I was
> working with DFL and cairo, and was using DFL's color structure.
> Problem was that DFL's stored using ubytes, and I wanted doubles.
> 
> So when I was writing my own colour structure, as I was defining the
> storage, I wrote
> 
>> union
>> {
>>     struct { double r, g, b, a; }
>>     double[4] rgba;
>> }
> 
> And it suddenly hit me: I could add a tuple!

How's that? You add an alias Tuple!(something ) to the union?

> Now, I have .tuple members for my colour structs, vectors, quaternions,
> matrices, and just about every other aggregate type I've written.
> 
> One thing that would make this an order of magnitude more useful would
> be the ability to return a tuple from a function.
> 
> But I agree: it's cool :)
> 
> 	-- Daniel
> 
> P.S.  I use .tuple instead of .tupleof because I don't want to shadow
> the very-useful compile-time property :)

I'm just using the compiler's .tupleof property directly.

--bb



More information about the Digitalmars-d mailing list