Boost logo

Boost :

Subject: Re: [boost] a safe integer library
From: David Stone (david_at_[hidden])
Date: 2015-12-17 02:16:30


I have written a similar library (http://doublewise.net/c++/bounded/), and
I have a few questions about your implementation.

You have a few policies for what to do on overflow. In particular, I see
you have throw_exception and trap_exception. trap_exception provides a
compile-time error instead of a run-time error. Could you explain this a
little bit more?

In my library, conversions for which the type is definitely in range (for
instance, [1, 6] assigned to [0, 10]) are implicit and no check is
performed. Conversions for which the type is possibly in range are explicit
and the policy is applied (run-time check). Conversions for which the type
is definitely out of range are a compile-time error, unless the overflow
policy says that overflow is not an error.

Your overflow policies all seem to assume overflow is error. How difficult
would it be to add in the ability to provide 'clamping' or 'saturation'
behavior? If you go below the min, set the value to the min, and if you go
above the max, set to the max. Similar question for a modulo policy, which
gives you the same behavior as unsigned integers.

I will have more thoughts later as I read the rest of the documentation.


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