L
Lo?c Henry-Gr?ard
Hi,
I'm using a homebrew, lightweight version of SIunits, the physical
dimension checker. For example I define types such as m (meters), s
(seconds) and mps (meters per second) in namespace SI and I have all
the overloadings of operator* such as
SI::m operator* (SI::s, SI::mps)
{ ... }
saying that a velocity multiplied by a time yields a distance.
On the other hand, before I had implemented the dimension checking, I
was using a generic three dimension vector type with an operator*
vec<T1> operator* (T2 a, vec<T1> b) { return vec<T1> (b.x * a, b.y *
a, b.z * a) ; }
Now of course if I cannot multiply a time by a vector of speeds and
automatically get a vector
of distances, since the template tries to instanciate
vec<SI::mps> operator* (SI::s a, vec<SI::mps> b)
which is not dimensionally correct.
I'm not familiar with the full-blown implementation of SIunits, even
though I use the same basic idea of a template parameterized by ints
giving the exponent of the unit in each dimension.
I don't know if their implementation allows an elegant implementation
of a generic vector class that would work transparently for normal
scalar types and for dimension-checked units, e.g.
that would implement
vec<SI::m> operator* (SI::s, vec<SI::mps>)
But since my problem looks quite common I thought someone might have
an idea of the most elegant way to do that.
I'm using a homebrew, lightweight version of SIunits, the physical
dimension checker. For example I define types such as m (meters), s
(seconds) and mps (meters per second) in namespace SI and I have all
the overloadings of operator* such as
SI::m operator* (SI::s, SI::mps)
{ ... }
saying that a velocity multiplied by a time yields a distance.
On the other hand, before I had implemented the dimension checking, I
was using a generic three dimension vector type with an operator*
vec<T1> operator* (T2 a, vec<T1> b) { return vec<T1> (b.x * a, b.y *
a, b.z * a) ; }
Now of course if I cannot multiply a time by a vector of speeds and
automatically get a vector
of distances, since the template tries to instanciate
vec<SI::mps> operator* (SI::s a, vec<SI::mps> b)
which is not dimensionally correct.
I'm not familiar with the full-blown implementation of SIunits, even
though I use the same basic idea of a template parameterized by ints
giving the exponent of the unit in each dimension.
I don't know if their implementation allows an elegant implementation
of a generic vector class that would work transparently for normal
scalar types and for dimension-checked units, e.g.
that would implement
vec<SI::m> operator* (SI::s, vec<SI::mps>)
But since my problem looks quite common I thought someone might have
an idea of the most elegant way to do that.