Exiv2
|
Arithmetic operations with overflow checks. More...
Namespaces | |
Internal | |
Helper functions for providing integer overflow checks. | |
Functions | |
template<typename T > | |
T | add (T summand_1, T summand_2) |
Safe addition, throws an exception on overflow. More... | |
Arithmetic operations with overflow checks.
T Safe::add | ( | T | summand_1, |
T | summand_2 | ||
) |
Safe addition, throws an exception on overflow.
This function returns the result of summand_1 and summand_2 only when the operation would not overflow, otherwise an exception of type std::overflow_error is thrown.
[in] | summand_1,summand_2 | summands to be summed up |
std::overflow_error | if the addition would overflow |
This function utilizes compiler builtins when available and should have a very small performance hit then. When builtins are unavailable, a more extensive check is required.
Builtins are available for the following configurations: