Boost logo

Boost :

Subject: Re: [boost] Is there interest in portable integer overflow detection, with policy based handling?
From: Ben Robinson (cppmaven_at_[hidden])
Date: 2012-02-22 10:50:18

> I haven't seen any code, so I can't see exactly what you're doing, nor
> have I spent any cycles thinking about the details that would apply in what
> you've described. However, I wrote a library that does range checked
> assignment, in a new-style cast form (checked_cast). It never requires
> more than two comparisons (against the target's maximum and minimum
> values), and there's no subtraction. I use TMP to determine signedness and
> relative size to determine which comparisons are needed. Obviously, types
> with the same signedness only require underflow or overflow detection when
> the target type is smaller than the source type. Thus, I'm concerned that
> your range tests are not as efficient as they could be. (Then again, what
> you've done might optimize better, for all I know. If so, be sure to
> document that in a Rationale section.)
> VerifiedInt contains the following four detection routines:


Overflow (positive and negative) are not possible with division and
modulus. The assignment detection routine performs exactly like yours,
requiring between zero and two comparisons, based on the signedness and
relative sizes of the data types using TMP.

I will definitely create a Rationale section when I start producing the

Thank you,

Ben Robinson

> _____
> Rob Stewart robert.stewart_at_[hidden]
> Software Engineer using std::disclaimer;
> Dev Tools & Components
> Susquehanna International Group, LLP

Boost list run by bdawes at, gregod at, cpdaniel at, john at