Boost logo

Boost :

From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2003-01-15 10:57:16


<Bjorn.Karlsson_at_[hidden]> wrote in message
news:3D8559AE95B4D611B02C0002557C6C8B3C45BF_at_STH-EXCH...
> > From: Thorsten Ottosen [mailto:nesotto_at_[hidden]]
> >
> > Hi Boosters,
> >
> > I was wondering if it would be possible to implement a wrapper around
> > built-in types to provide automatic detection of conversion
> > problems:
>
> [snip]
>
> What would the advantage be over using boost::numeric_cast directly, and
> thus explicitly? Using these wrappers, it wouldn't be obvious that there
are
> numeric_casts involved (implying possible failure [and therefore try/catch
> blocks for bad_numeric_cast]).

you would't have to worry about if you forgot a numeric_cast somewhere in
your code
or if you compiled on a platform with different ranges for built-ins which
suddenly
could make conversion problems appear.

> As I see it, automatic detection of
> conversion problems wouldn't buy much unless it could also remedy the
> problem.

that depends on what the "problem" is. I would say that an _undetected_
false conversion
is the biggest problem.

>Doing it "manually", and acknowledging the potential problem by
> using numeric_cast is (in addition to ensuring correct behavior)
> self-documenting, a property that I think is rather important.

by using a wrapper, you also acknowledge a potential problem.

I might also be beneficial when you are chaning a variable from one type to
another; the change
might cause conversion problems some different place in the code and/or
require numeric_cast
to be inserted. By using wrappers this would be detected.

regards

Thorsten


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