
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:
detect_overflow_impl_assignment detect_overflow_impl_addition detect_overflow_impl_subtraction detect_overflow_impl_multiplication 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 documentation. Thank you, Ben Robinson
_____ Rob Stewart robert.stewart@sig.com Software Engineer using std::disclaimer; Dev Tools & Components Susquehanna International Group, LLP http://www.sig.com