Boost.units ported to D

bearophile bearophileHUGS at lycos.com
Mon Feb 11 11:08:13 PST 2013


Arlen:

> https://github.com/Arlen/phobos/blob/std_units/std/units.d
> docs: http://arlen.github.com/phobos/std_units.html

It seems a lot of work.
But code like this is not encouraging:


    Quantity!(si.Energy) work(Quantity!(si.Force) F, 
Quantity!(si.Length) dx)
    {
        return F * dx;
    }

    void main()
    {
        Quantity!(si.Force)  F  = 2.0 * si.newton;
        Quantity!(si.Length) dx = 2.0 * si.meter;
        Quantity!(si.Energy) E  = work(F, dx);
        writefln("F  = %s\ndx = %s\nE  = %s\n", F, dx, E);

        alias Complex!double ComplexType;

        Quantity!(si.ElectricPotential, ComplexType) v = 
complex(12.5, 0) * si.volts;
        Quantity!(si.Current, ComplexType)           i = 
complex(3, 4) * si.amperes;
        Quantity!(si.Resistance, ComplexType)        z = 
complex(1.5, -2) * si.ohms;


I think units are something that needs a good syntax to have a 
chance to be used :-(

Bye,
bearophile


More information about the Digitalmars-d mailing list