Boost logo

Boost :

From: Kevlin Henney (kevlin_at_[hidden])
Date: 2000-12-07 04:11:17


In message <v03110701b654be52d4c8@[153.32.222.4]>, Jesse Jones
<jejones_at_[hidden]> writes
>numeric_cast OTOH is very useful and not quite as trivial. I use something
>like it in my own code. The only question I have is whether it should throw
>or assert on failure. In my own code a failure almost always indicates a
>programmer error so I'd prefer the assert.

It should be a runtime failure rather than a debugging issue as there
are many conversions that cannot be conveniently checked ahead of use --
to do so would require near duplication of all the code that makes up
numeric_cast :->

One could also argue that there would be little point in having
numeric_cast if it trapped only in debug mode. Might as well use
static_cast and see if you get the right results in your unit tests --
if not, you have a conversion bug! ;-)

And finally, there is the point that, as a checked cast, numeric_cast is
consistent with the existing language. The example it follows closest is
dynamic_cast<T &>.

Kevlin
____________________________________________________________

  Kevlin Henney phone: +44 117 942 2990
  Curbralan Limited mobile: +44 7801 073 508
  mailto:kevlin_at_[hidden] fax: +44 870 052 2289
  http://www.curbralan.com
____________________________________________________________


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk