|
Boost : |
From: Matthias Schabel (boost_at_[hidden])
Date: 2007-02-16 17:27:44
> if (aircraft.altitude > ground_elevation + min_agl_offset)
>
> as
>
> if (unit_cast<elevation_type>(aircraft.altitude) > ground_elevation +
> min_agl_offset)
This is actually a very good example of the problem; here there are
two steps,
the addition operation and the comparison. Without specifying a priori a
particular common base unit system through which all conversions are
mediated (which is basically the same as requiring everyone use one unit
system), this is just fundamentally ambiguous - it has nothing to do
with
implementation. If I ask :
Is 3 feet plus 1 meter less than one fathom?
How would you answer it? Naturally, you would want to convert to some
common unit of length, but which one? There are three choices, and all
are roughly equivalent. Now, in this case, it doesn't matter since
all three
systems would give you the same answer, but since there is no good way
for the compiler to make this decision automatically,the reasonable
thing
for it to do is issue an error. this problem doesn't go away if you have
runtime units either - it is just fundamentally bad practice to have the
compiler make arbitrary decisions in arithmetic expressions.
Matthias
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk