Boost logo

Boost :

From: vladimir josef sykora (vladimir.sykora_at_[hidden])
Date: 2002-10-17 04:36:51


"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?

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;

>
> [some of the example deleted]
>
>
> >int main(int argc, char* argv[])
> >{
> > some_unit_t some_unit(10.0);
> > some_other_unit_t some_other_unit(20.0);
> > product_result_t product_res(some_unit*some_other_unit);
> > std::cout << product_res << std::endl;
> >}
> >
> > output :
> > 20 s^-2 kg^2 m^3
>
> <nit>
> Since the SI used to be called mks I would expect the units to be
published
> in length, mass, time order rather than the other way round.

Just a matter of swap 3 lines.

>(btw, what
> measure is m^3 kg^2 s^-2 ?)
> </nit>

It was used just for explanatory purposes, to show how the conversions and
the typelists works.

>
>
>
> >_______________________________________________
> >Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
>
> Victor A. Wagner Jr. http://rudbek.com
> PGP RSA fingerprint = 4D20 EBF6 0101 B069 3817 8DBF C846 E47A
> PGP D-H fingerprint = 98BC 65E3 1A19 43EC 3908 65B9 F755 E6F4 63BB 9D93
> The five most dangerous words in the English language:
> "There oughta be a law"
>
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
>


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