Boost logo

Boost :

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


In message <00a701c06053$037d4fb0$0500a8c0_at_[hidden]>, David
Abrahams <abrahams_at_[hidden]> writes
>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);

Yes, this seems good. The cast form could wrap around this, and make use
of the conversion result to create a more meaningful exception. In the
dim and distant past a version of numeric_cast did report more specific
errors through different exceptions. It would be nice to have a
consistent scheme for this, and I think this is it.

This suggests that perhaps we should either rebrand the cast library the
conversions library, with cast-like functions simply being one of the
offerings, or break out the numeric stuff into a separate header to let
it grow a little.

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