Boost.units ported to D
Arlen
arlen.ng at gmx.com
Mon Feb 11 12:07:14 PST 2013
On Mon, Feb 11, 2013 at 1:19 PM, Michael <pr at m1xa.com> wrote:
> It is possible write something like?
>
> auto force = 2.0 * SI.Newton;
>> auto energy = force * 2.0 * SI.Meter;
>>
>
>
Yes because typeof(2.0 * si.newton) is Quantity!(si.Force) and typeof(force
* 2.0 * si.meter) is Quantity!(si.Energy). In the future when the unit
systems are placed in their own modules, you could alias away and say:
auto force = 2.0 * newton;
auto energy = force * 2.0 * meters;
Also note, 'newton' and 'meter' are instances of Unit. You could define
your own and give whatever name you like. For example:
si.Length myMeter;
auto x = 3.0 * myMeter;
writeln(x); // prints '3 m'
In std.units I had to make the instances manifest constants (using
instanceOf mixin) because they are in structs. That will probably change
in the future if each system is placed in its own module. In that case
std.unit will have to become a package, and I'm not sure if packages are
allowed in Phobos. Anyone know?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130211/95981b4d/attachment.html>
More information about the Digitalmars-d
mailing list