Boost logo

Boost :

Subject: Re: [boost] [numeric_cast] request for boost::numeric_downcast
From: Kim Barrett (kab.conundrums_at_[hidden])
Date: 2008-11-14 17:22:34


At 2:57 PM +0100 11/14/08, Thorsten Ottosen wrote:
>Kim Barrett skrev:
>>At 2:41 AM -0500 11/11/08, David Abrahams wrote:
>>>boost::polymorphic_downcast is meant to be used where you think you
>>>really know what derived type you've got, and you want an assertion to
>>>reinforce your reasoning with a runtime check. I suppose you can have a
>>>similar situation for numeric types (e.g. "I know this long int should
>>>fit in a short int").
>>>
>>>How about boost::checked_cast, or boost::checked_narrowing_cast or
>>>boost::narrow_cast?
>>
>>Is this any different from boost::numeric_cast with an asserting rather
>>than throwing overflow handler, plus boost/numeric/conversion paying
>>attention to BOOST_NO_EXCEPTIONS, possibly by using boost::throw_exception?
>
>It depends. I can't remember how the overflow handler mechanism
>works, but we need to be able to have both types of casts in the
>same program.

The asserting form of cast can pretty clearly be implemented using the
overflow handler mechanism, so having both types of casts in the same
program is supportable.

My recollection is that the OP wanted something that works in a program
compiled without exception support. I think that if the existing throwing
default overflow handler were to use boost::throw_exception rather than
directly using throw that the right thing should happen.


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