Boost logo

Boost :

From: Darin Adler (darin_at_[hidden])
Date: 1999-09-19 18:30:38


John Maddock:
> Doesn't numeric_cast already do want you want for narrow_cast<> ?

First, an aside: My point wasn't that my narrow_cast should be added to
casts.hpp, but rather that implicit_cast ought not to disable implicit
numeric conversion warnings.

However, there are two dimensions in which my narrow_cast is different from
numeric_cast.

1) Behavior when the source value doesn't fit in the destination type:

    - numeric_cast throws a bad_numeric_cast exception
    - narrow_cast quietly does what static_cast would do (standard-defined
for some combinations, implementation defined for others)

2) Behavior when the destination type is wider than the source type:

    - numeric_cast works, but may generate redundant code for these cases on
some compilers
    - narrow_cast won't link; helps keep unnecessary narrow_cast calls out
of code

What the two casts have in common is the fact that neither generates
"implicit numeric conversion" warnings on compilers that support them.

I'm trying to address cases where people are using implicit_cast to quiet
"implicit numeric conversion" warnings. I think they should be using either
numeric_cast or something like narrow_cast instead, and I'd like to ensure
that implicit_cast does not quiet those warnings.

    -- Darin


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