Boost logo

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
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
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.


Boost list run by bdawes at, gregod at, cpdaniel at, john at