Boost logo

Boost :

Subject: Re: [boost] SafeInt code proposal
From: Ilya Bobir (ilya.bobir_at_[hidden])
Date: 2009-06-20 20:01:30

Omer Katz wrote:
> A friend and I have started working on a SafeInt library which we hope
> will be included in Boost
> the library is composed of a template class, which excepts existing
> integer types as a parameter, and an exception class.
> not all operators have been implemented and there is still work to be
> done on the library, but we have reached a stage in which at least the
> basic operators are ready and tested.
> I've attached to this thread a zip file containing the code for the
> library and a tester we wrote (as an example for how the class should be
> used)
> I've also uploaded it to the boost vault.
> We would appreciate it if you took the time to review our code and give
> us your comments, tips and opinions (either as a reply to this thread or
> by email - omerktz_at_[hidden])

I really doubt that you library will be accepted in its current form.
For the following reasons:

1. The SafeInt objects are 3 time larger than the integer they wrap.
max_value and min_value can be static - they really depend only on the
type of the integer you wrap. Not on the value that is currently contained.

2. Default constructor does 1 or 2 pow calls. You can use << to get a
power of 2.

3. Many checks that are performed currently at run time can be done at
compile time.

4. x86 has hardware support for checking for integer overflows. It
means that the OS may provide some means to check if an overflow has
occurred. Using hardware may be way faster then doing the checks in the

P.S. Your code seems to be very similar to what is published here:

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