PROPOSAL: Operator overloading by static member function

Daniel Keep daniel.keep.lists at gmail.com
Sat Oct 13 23:55:00 PDT 2007



Janice Caron wrote:
> On 10/14/07, Janice Caron <caron800 at googlemail.com> wrote:
>> On 10/14/07, Daniel Keep <daniel.keep.lists at gmail.com> wrote:
>>> auto distance = 20*m;
>> Oh that is cool!
> 
> I guess you could generalise that...
> 
> auto area = 100*m*m;
> auto velocity = 50*m/s;
> const G = 6.673e-11*m*m*m*/kg/s/s;
> 
> ....and even do unit conversions...
> 
> auto distance = 15*miles; /*converts to meters*/
> 
> Super duper. OK, I'm all in favor of keeping thing the way they are,
> coz that's just so brilliant.

I did something similar in Python once (called it "Units") but got
caught up on how exactly to encode transforms between different systems.

Actually, I believe someone's done something like this for D before.
Their goal, however, was *compile-time* checking of units.  So, for
example, you couldn't do this:

auto v = 3*m/s;
auto a = 9.81*m/(s*s);
auto huh = v+a;

	-- Daniel



More information about the Digitalmars-d mailing list