Exiv2
|
Helper structs for providing integer overflow checks. More...
Classes | |
struct | builtin_add_overflow |
Overflow checker using compiler intrinsics. More... | |
struct | enable_if |
Helper struct for SFINAE, from C++11. More... | |
struct | enable_if< true, T > |
Specialization of enable_if for the case B == true. More... | |
struct | fallback_add_overflow |
Fallback overflow checker, specialized via SFINAE. More... | |
struct | fallback_add_overflow< T, typename enable_if< is_signed< T >::VALUE >::type > |
Overload of fallback_add_overflow for signed integers. More... | |
struct | fallback_add_overflow< T, typename enable_if<!is_signed< T >::VALUE >::type > |
Overload of fallback_add_overflow for unsigned integers. More... | |
struct | is_signed |
Helper struct to determine whether a type is signed or unsigned. More... | |
Helper structs for providing integer overflow checks.
This namespace contains the internal helper structs fallback_add_overflow and builtin_add_overflow. Both have a public static member function add with the following interface:
bool add(T summand_1, T summand_2, T& result)
where T is the type over which the struct is templated.
The function performs a check whether the addition summand_1 + summand_2 can be performed without an overflow. If the operation would overflow, true is returned and the addition is not performed if it would result in undefined behavior. If no overflow occurs, the sum is saved in result and false is returned.
fallback_add_overflow implements a portable but slower overflow check. builtin_add_overflow uses compiler builtins (when available) and should be considerably faster. As builtins are not available for all types, builtin_add_overflow falls back to fallback_add_overflow when no builtin is available.