From: Dejan Jelovic (djelovic_at_[hidden])
Date: 2001-04-12 13:54:42
On September 23, 1999, NASA lost the Mars Climate Orbiter just as it was
starting to circle the planet. The cause was a failure to convert
navigational data from the English units used by one group of technicians to
the metric units used by another.
In order to avoid problems like this in my programs, I've developed a
template class called arithmetic_type_wrapper. It provides a thin wrapper
around primitive types like int and double but lets you define different
types to represent different things.
For example, say you have to do some calculation in meters and feet and want
to represent different units with different types. The code for something
like that would be:
typedef arithmetic_type_wrapper<double, meters_tag> meters;
typedef arithmetic_type_wrapper<double, feet_tag> feet;
meters m = meters (10) + meters (20); //ok
feet f = feet (5) + feet (10); // ok
meters (10) + feet (20); // oops, compile-time error
Is there any interest in adding this to Boost?
P.S. I usually demonstrate this with apples and oranges, but then noone
takes me seriously :).
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk