Boost logo

Boost :

From: vladimir josef sykora (vladimir.sykora_at_[hidden])
Date: 2002-10-16 11:57:58


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.
The library compiles on gcc 3.2. Still has some nasty behavior on Borland
(the ices are buried deep inside templated code).
I'd like to hear if there's any interest in the library. I think it'll fit
great with a physical constants library. I've uploaded the zip file here:

http://groups.yahoo.com/group/boost/files/Physical_Units_Library.zip

Here's an example of the syntax for creating unit's types:

using namespace morpho;
typedef TL_generator<meterPolicy<>,3,gramPolicy<kilo>,2,secondPolicy<>,-2,
    amperPolicy<>,0,kelvinPolicy<>,0,molPolicy<>,0,luxPolicy<>,0>::type
some_unit_tl;
typedef TL_generator<footPolicy<>,1,poundPolicy<>,-3,minutePolicy<>,3,
    amperPolicy<>,0,kelvinPolicy<>,0,molPolicy<>,0,luxPolicy<>,0>::type
some_other_unit_tl;

typedef unit<double, some_unit_tl> some_unit_t;
typedef unit<double, some_other_unit_tl> some_other_unit_t;

typedef op_generators::product::apply<some_unit_t,some_other_unit_t>::type

product_result_t; // converts to the lhs policies and value_type

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


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