Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-10-26 18:20:54


----- Original Message -----
From: Darin Adler <darin_at_[hidden]>
To: Boost <boost_at_[hidden]>
Sent: Friday, October 26, 2001 8:10 PM
Subject: Re: [boost] casts, exceptions, and asserts

> on 10/26/01 4:09 PM, Fernando Cacciola at fcacciola_at_[hidden] wrote:
>
> >> That would be a conversion that asserts
> >> that no precision is lost. The current conversion throws an exception
if
> >> the result is out of range, but having one that asserts if the result
loses
> >> precision would be useful too, I think.
> >>
> > Yes. I considered this too, but leave it out because the implementation
is
> > rather involved; and I didn't want to scare people out with too much
> > complexity
>
> Ah, we are talking about two different things.
>
> I was thinking of something that would assert if the result could possibly
> lose precision due to the types involved. No runtime check at all, just a
> compile time check. For generic programming only.
>
If I interpreted you correctly now, this is already supported.

numeric_cast_traits<S,T>::subranged is true if the conversion could loose
precision.
you can wrap that in a static_cast<>

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com


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