|
Boost : |
From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2002-10-17 08:49:54
>From: "vladimir josef sykora" <vladimir.sykora_at_[hidden]>
> "Victor A. Wagner, Jr." <vawjr_at_[hidden]> wrote in message
> news:4.3.1.2.20021016215823.057410a8_at_mail.rudbek.com...
> > At Wednesday 2002/10/16 09:57, you wrote:
> > >Greetings boosters,
> > >I've been working for some time now on a physical unit's library that
I'd
> > >like to submit to boost. It uses the concept of generating units out of
> > >physical dimensions. It provides type-safety and implicit conversion
> between
> > >units using operators.
> > >The unit's dimension orders are static constant integers and are
> calculated
> > >on compile-time (using mpl); however, the conversion between the unit's
> > >values are calculated on run time. The coversion between pure units is
> > >policy-driven and is easy to add more pure-units to the policies.
> >
> > I like the idea... I've heard that there is some code at FermiLab that
may
> > do the same thing, have you looked at it?
I find this interesting, too.
Does anyone have any pointers to info on FermiLab's SIUnits? I've done a
search, and one page I found was a paper on it
(http://216.239.39.100/search?q=cache:Ml9XMuYb-CsC:oonumerics.org/tmpw01/bro
wn.pdf&hl=en&ie=UTF-8) (It appears that oonumerics is down, so the original
pdf wasn't available).
> Our idea was to use MetaProgramming-framework to create a units' library;
is
> where our ideology diverge from Fermilab's lib. The use of policies makes
> easy to add more pure-units.
> Let me explain better the syntax:
>
> typedef TL_generator<meterPolicy<>,1,gramPolicy<kilo>,1,secondPolicy<>,-2,
> amperPolicy<>,0,kelvinPolicy<>,0,molPolicy<>,0,luxPolicy<>,0>::type
> newton_type_list;
> ^ ^
> ^
> pure unit's policy
multiple
> dimension's order
>
> here we are creating out of 3 pure units (kilogram, meter, second) a
derived
> unit: newton.
> This orthogonalization lets us create an immense ammount of units, with a
> linear ammount of code; we just have to add the pure-unit's policy that we
> want to work with.
> Now we create the unit with the typelist and the value type:
>
> typedef unit<long double, newton_type_list> newton_type;
According to the mentioned paper, this is possible in SIUnits, too. To quote
Figure 10 in the paper:
typedef MakeIntegralDim(1,0,0,0,0,0,0) LengthDim;
typedef MakeIntegralDim(0,0,1,0,0,0,0) TimeDim;
typedef ListCombine<LengthDim,RatioDiv,TimeDim>::Ans VelocityDim;
Your version appears simpler, though. Unless it's possible to do it like
this in SIUnits:
typedef MakeIntegralDim(1,1,-2,0,0,0,0) Newton;
One question: How would you attach symbol and name to the new unit (if
possible), i.e. "N" and "newton"?
Also, how do you output the name of such derived units, and non-SI units,
such as "foot"?
Regards,
Terje
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk