Boost logo

Boost :

From: Deane Yang (deane_yang_at_[hidden])
Date: 2003-10-14 11:11:27

I did take a quick look, so I might have gotten the wrong idea. Please
forgive me if I did. It appeared to me that your approach,
using a list of integers, is limited to a preselected choice of
dimensions. This works well in physics, where one knows in advance
pretty much all dimensions that one is going to need.

On the other hand, Hugo's approach would appear to allow for
compile-time definition of dimensions:

"It defines
a quantity as a numeric type and a set of dimensions

   template <typename T, typename Dimensions> class quantity;

where dimensions contains a mpl type sequence, with each
element holding instances of

   template <
       typename DimensionType
     , long Numerator
     , long Denominator=1
> struct dimension_power

Each DimensionType is then assosciated with a unit."

The other quibble is that I also need fractional powers
of dimensions.

To be honest, I haven't looked at Hugo's explanation in detail
yet, and given my poor grasp of mpl, I think it will take some
effort. I don't even know how to add fractions and reduce to lowest
terms in mpl yet. (Or maybe you don't try to reduce and you just test
for equality of fractions when you multiply two quantities. That sounds
a lot easier.)

Through what little experience I have in programming, I've learned to
hate using raw numbers like doubles in numerical computations in any
circumstance, even if is a pure mathematical calculation. It is way
too easy to get the "units" wrong (and, yes, the concept of "units" do
sometimes exist even in pure mathematics) and real headache to debug.
I would like to develop a units library that I can use under any
circumstances with complete flexibility. I really, really like letting
the compiler debug my code for me. I don't know if it saves me any time,
but it sure saves wear and tear on my brain.

David Abrahams wrote:
> Deane Yang <deane_yang_at_[hidden]> writes:
>>(Detailed explanation by Hugo Duncan about how to implement a
>>dimensions library using mpl deleted)
> I don't see any MPL usage (other than conventions) in Hugo's
> example. Did you look at my slides?

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