Boost logo

Boost :

From: Matthias Schabel (boost_at_[hidden])
Date: 2004-01-10 14:32:20


>> // test ideal gas law
>> SI<double>::temperature T = (273.+37.)*_kelvin;
>> SI<double>::pressure P = 1.01325e5*_pascals;
>> SI<double>::length r = 0.5e-6*_meters;
>> SI<double>::volume V = (4.0/3.0)*3.141592*power<3>(r);
>> SI<double>::quantity n(idealGasLaw(P,V,T));
>
> But isnt this a bit runtime-slow Matt?

Not unless the compiler can't inline away the trivial multiplication;
the various
constants defining dimensioned units (_kelvin, _pascals, etc...) are
instances of
an empty class - no data members - so the multiplication is just a way
of getting
the type information to propagate in the runtime system to make this
sort of syntax
possible. In other words, looking at the first line,

SI<double>::temperature

is a dimensioned_quantity (value plus dimensioned unit)

_kelvin

is a dimensioned_unit, a class with no data members, and the
multiplication operator
just decorates the value passed to it (273.+37.) with the appropriate
unit information.

> BTW I looked into your ct problems. VC 7.1 has some neat
> specialisations.
> (Doesnt work on gcc)
> have you tried masks?
> Basically 7 dimensions --> 127 (I think) mask possibilities
> If interested Will try to look out the code.

Not sure how that will help with user-defined quantities outside of SI.
  I suppose if one
was willing to enumerate every allowable tag class, it would be
possible to have two
mpl::vectors, one with the integer indices of the tags and another with
the exponents.
I think at this point I'm going to stick to my efforts to improve
compile time through use
of mpl::set and see where that gets me...

------------------------------------------------------------------------
---------------------------
Matthias Schabel, Ph.D.
Utah Center for Advanced Imaging Research
729 Arapeen Drive
Salt Lake City, UT 84108
801-587-9413 (work)
801-585-3592 (fax)
801-706-5760 (cell)
801-484-0811 (home)
mschabel at ucair med utah edu


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk