How to have strongly typed numerical values?

Simen Kjaeraas simen.kjaras at gmail.com
Tue Sep 4 22:03:53 PDT 2012


On Wed, 05 Sep 2012 02:55:45 +0200, Nicholas Londey <londey at gmail.com>  
wrote:

> Hello.
> I am trying to work out if there is existing support for strongly typed  
> numerical values for example degrees west and kilograms such that they  
> cannot be accidentally mixed in an expression. I have vague recollection  
> of seeing a presentation by Walter talking about this but I cannot seem  
> to find it. I have looked at std.typecons.Typedef and Proxy but neither  
> seem to do what I want or at least fail to compile for the expression n  
> =  n + n;. I could easily implement my own as I have done in C++ in the  
> past but assume there is a standard implementation which I would prefer.
> Any help or links to examples much appreciated.
>
> Regards,
>
> Nicholas

Not mine, but this is the implementation I use:

https://github.com/klickverbot/phobos/tree/units/std

Files are units.d and si.d.

Documentation:
http://klickverbot.at/code/units/std_units.html
http://klickverbot.at/code/units/std_si.html

-- 
Simen


More information about the Digitalmars-d-learn mailing list