From: David Richardson (dgr24_at_[hidden])
Date: 2003-10-08 14:23:11
Is there any interest in a class for compile time checking of
dimensional correctness of arithmetic expressions? It is a great
debugging aid for scientific and engineering code.
I've written a library that supports exponentiation, arithmetic,
comparisons, and user defined units on a class that enforces
dimensional correctness via its assignment and arithmetic
operators. It can be used as
f = m*a; //this is just fine
f = m/a; //this will produce a compiler error.
All of the validation is done at compile-time using templates.
Theoretically this should mean there is no runtime overhead.
There is also a preprocessor directive to completely turn off
There have been previous implementations of libraries like this,
but they don't seem to be maintained anymore. They also don't
appear to be advertised very much, as scientists and engineers
I've talked to weren't aware of them. (see
http://www.cs.binghamton.edu/~zdu/dim/ and the book C++ Scientific
and Engineering C++ : An Introduction with Advanced Techniques and
Making something like this more widely available would be useful
for scientific programmers using C++. If there is any interest in
this, I'd be willing to submit what I have for a formal review.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk