Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-12-07 08:38:29

----- Original Message -----
From: "Kevlin Henney" <kevlin_at_[hidden]>

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

Good point!

Reviewing my own submission, one thing I might like to see someday is a way
to report conversion failures that doesn't involve exceptions. Sometimes you
just want to ask the question "does this value fit in a T?" and the answer
needs to be handled locally even if it's no (e.g. "OK, in that case I'll do
the computation with a BigNum"). For these situations, an exception doesn't
seem as appropriate. I guess the interface to that function should be
something like:

enum conversion_result { no_error, underflow, overflow, loss_of_precision };
template <class T, class U>
pair<U, conversion_result> convert_number(const U& x);


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