Boost logo

Boost :

From: Robert Kawulak (kawulak_at_[hidden])
Date: 2005-09-23 05:01:58


Hi,

I forgot to mention one important fact - when people talk about a bounded
integer class, what they usually mean is two different matters for real:
1. A class, which doesn't allow its values to fall out of a specified range,
2. A class, for which all integer operations are safe, because it handles
all the overflows etc.

For the sake of universality I've decided to separate the two concepts, and
my implementation focuses on the first one only, allowing also non-integral
types to be used. The second concept is very difficult to implement in a
portable way (as previous discussions on c.l.c++.m and c.s.c++ have shown),
quite good but highly non-portable example of a class dealing with this
problem can be found here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncode/html
/secure01142004.asp. Then such SafeInt class can be used as the bounded
template parameter to form a type which takes care of both the problems.

The implementation of bounded templates is missing one thing - the checks of
correctness of given bounds. In case of integral types there should be some
compile time assertion firing when somebody tries to instantiate the
template with bounds, say, 10 and 0 (which is not a valid range), in case of
non-integral types there should be some logic_error exception thrown. I just
can't figure out where is the best place to put the assertions, I'm afraid
that this requires a little change of the design. Anyway, let me think more
about it... :)

Best regards,
Robert


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