|
Boost : |
From: Jan Langer (jan_at_[hidden])
Date: 2004-01-05 16:05:09
Daniel Frey wrote:
> speed = length/time
>
> (which you can't use that way directly, as C++-types don't work that
> way) and
>
> mph = mile/hour
>
> The former can probably be written like this:
>
> typedef divide< length, time >::type speed;
i think that this is the point up to which most people interested in a
units/phys. dimensions library agree. there is a need for a type which
could be called dimension which provides mathematical functions like:
add <dim1, dim2> == dim1, assert (dim1 == dim2)
multply <dim1, dim2> == dim1 + dim2 (like vector addition)
divide <dim1, dim2> == dim1 - dim2
power <dim1, exponent> == exponent * dim1 (like scalar * vector)
where dim1 and dim2 are compile time lists (of any kind), which map
between a tag for each dimension and a (rational) compile time value,
representing the order of this dimension.
this stuff is easily done with mpl. and david a.'s slides are doing it.
although it might not be so easy to do it efficiently (thats probably a
weak point in matthias' implementation).
an easy way must be provided to define the dimensions for a special user
defined system. this system must also be tagged somehow so that if two
systems like
namespace si {
typedef dimensions::dim1 length;
typedef dimensions::dim2 time;
...
}
namespace my_system {
typedef dimensions::dim1 apples;
typedef dimensions::dim2 oranges;
}
exist, quantities of apples the a length cannot be added by chance.
then there is a need for a quantity type which brings together a
specific dimension, a value type (which i am sure should not be of type
double implicitly as implemented by andy, IMHO) and a member of that
value type.
this quantity type will allow all reasonably operations (+,*, /=, ...),
check them at compile time and forward them to its member.
now its IMHO not clear how units itself fit into the picture and what
the syntax of this quantity will be. this is the point which is done
differently in the existing implementations. maybe it could be explained
by matthias and andy, because its quite difficult to see their concept
behind the implementation when just looking at the code.
my personal opininion is to assume the value type to be measured in the
base unit of the system. then the units itself like meters and seconds
are just constants:
quantity <si::length> meter;
but it is still not clear what happens to the value type now. or in
other words, what type is the actual number in 5*meter.
si::meter<double> as a constant would be nice but is not possible (at
least with my knowledge) from an implementation point-of-view.
i hope to start a discussion on this point and not endless threads about
implementational corner cases or theoretical definitions (like the
angle thread).
jan
-- jan langer ... jan_at_[hidden] "pi ist genau drei"
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk