Cool thing about D, number #72

janderson askme at me.com
Sun Apr 29 11:42:52 PDT 2007


Georg Wrede wrote:
> janderson wrote:
>> Bill Baxter wrote:
>>
>>> I've always had this dilemma in C++ when writing graphicsy methods, 
>>> whether a function that takes a point should take separate components 
>>> (float,float,float) or a vector (Vec3f), or perhaps a pointer 
>>> (float*).  In D there's also the option of float[3].  Or just for 
>>> convenience sake maybe overloads for all of the above.
>>>
>>> I just realized today the coolness of tupleof for this kind of 
>>> situation.  You can make the function takes the plain floats
>>>
>>>    do_something_at_point(float x, float y, float z);
>>>
>>> And still call it using a Vec3f via tupleof!
>>>
>>>    Vec3f world_origin;
>>>    ...
>>>    do_something_at_point(world_origin.tupleof);
>>>
>>> as opposed to
>>>
>>>    do_something_at_point(
>>>        world_origin.x,
>>>        world_origin.y,
>>>        world_origin.z);
>>>
>>> It's a minor thing, but it rocks.
>>
>> I think it would be cool if we had a D.algorithms newsgroup; but then 
>> again, I think I'd never visit this newsgroup :)
> 
> In six months I'l go "man there was this thing about using .tupleof when 
> passing arguments, but I'm damned if I can't find it". Happens to me all 
> the time.
> 
> I wonder, is there someplace where gems, nifty things, gotchas, etc. are 
> collected from these newsgroups?
> 

Start a wiki page?



More information about the Digitalmars-d mailing list