Boost logo

Boost :

From: Matthias Schabel (boost_at_[hidden])
Date: 2007-01-20 13:04:43

Hi Noah,

> Would something like this work for creating a quantity that's unit can
> change during runtime and allow support for multiple units all
> converting to a particular "system" (as you specify the meaning)?

I am drawing a "line in the sand" at implementation of runtime unit
this is not because it can't or shouldn't be done, but because it is
a completely different problem domain with different objectives and
performance criteria. It would certainly be possible to integrate a
runtime unit
and quantity library, if someone else wanted to implement it, with my
library by simply specializing the unit and quantity classes
something like this:

struct runtime_system { };
struct runtime_dim { };

template<> class unit<runtime_system,runtime_dim> { ... };

typedef unit<runtime_system,runtime_dim> runtime_unit;

template<class Y> class quantity<runtime_unit,Y = double> { ... };

That being said, it is possible to have compile-time units with
runtime varying
unit conversions (as I alluded to in the previous post on currency
You basically need to specialize the conversion_helper class (in
to do what you want it to...

> For instance, I work on fluid flow analysis programs and have started
> working on a unit library based on ch. 3 in the MPL book. One thing I
> need is for user entry of arbitrary (and sometimes user defined)
> units.
> So an entry of pressure might be in psi or inches of mercury; it
> also
> might be in gage (with some user defined reference atmospheric
> pressure)
> or absolute. These values need to be stored in those units (otherwise
> you run afoul of float migration) and are the ultimate entry data
> parameters for all the system's equations. How does your library meet
> this need?

My library does not deal with issues of runtime units, therefore,
does not
provide any facility for doing these sorts of things. I do believe
that this is
an interesting area, and potentially worthy of implementation, but I
have the time, inclination, or expertise to do it. I would like to
keep the focus
in the present discussion on zero runtime overhead dimensional analysis
systems and reserve consideration of runtime units for another time/

> Another issue we have is that equations are more often than not
> referenced from some source written in arbitrary units. It would be
> nice to be able to reflect this in code so that if some source says "*
> 9.32 psi a" this could be done in the code itself with minimal to 0
> impact on runtime performance. Does your library meet this need?
> I envision something akin to:
> typedef quantity<SI::pressure> length_qty;
> X f() { static length_qty const p9 = 9.32 * psi; }

There are various ways to accomplish this with the library; explicit
of units between unit systems would allow something like you wrote :

static quantity<SI::pressure> const p9(9.32*psi);

assuming you either

1) defined a pounds-inches unit system with appropriate conversions
to the SI


2) simply defined psi as a constant in SI units

Either option is probably acceptable; the former is best if many of
the program's
computations will be done in a pounds-inches system, the latter if
you are just
occasionally using non-SI units in a predominantly SI code.



Boost list run by bdawes at, gregod at, cpdaniel at, john at