Effective implementation of algorithms (Master Thesis)
Effective and error-free implementation of algorithms
|
00001 #ifndef H_UTILS_ASSERT_INTEGER_OVERFLOW 00002 #define H_UTILS_ASSERT_INTEGER_OVERFLOW 00003 00004 #include "utils/static_assert/static_assert.h" 00005 #include <limits> 00006 00026 template <typename SuppliedType, typename RequiredType> 00027 inline void STATIC_ASSERT_CHECK_INTEGER_OVERFLOW() { 00028 STATIC_ASSERT(std::numeric_limits<SuppliedType>::is_integer, 00029 "Invalid SuppliedType - should be integer"); 00030 STATIC_ASSERT(std::numeric_limits<RequiredType>::is_integer, 00031 "Invalid RequiredType - should be integer"); 00032 00033 // disallow signed->unsigned 00034 STATIC_ASSERT(std::numeric_limits<RequiredType>::is_signed 00035 || !(std::numeric_limits<SuppliedType>::is_signed), 00036 "Signed to unsigned overflow"); 00037 00038 // digits is enough to check (works with size of signed vs unsigned also). 00039 STATIC_ASSERT(std::numeric_limits<SuppliedType>::digits <= 00040 std::numeric_limits<RequiredType>::digits, 00041 "Possible overflow!"); 00042 } 00043 00044 #endif