Exiv2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Static Public Member Functions | List of all members
Safe::Internal::fallback_add_overflow< T, typename enable_if< is_signed< T >::VALUE >::type > Struct Template Reference

Overload of fallback_add_overflow for signed integers. More...

#include <safe_op.hpp>

Static Public Member Functions

static bool add (T summand_1, T summand_2, T &result)
 Adds the two summands only if no overflow occurs. More...
 

Detailed Description

template<typename T>
struct Safe::Internal::fallback_add_overflow< T, typename enable_if< is_signed< T >::VALUE >::type >

Overload of fallback_add_overflow for signed integers.

Member Function Documentation

template<typename T >
static bool Safe::Internal::fallback_add_overflow< T, typename enable_if< is_signed< T >::VALUE >::type >::add ( summand_1,
summand_2,
T &  result 
)
inlinestatic

Adds the two summands only if no overflow occurs.

This function performs a check if summand_1 + summand_2 would overflow and returns true in that case. If no overflow occurs, the sum is saved in result and false is returned.

Returns
true on overflow, false on no overflow

The check for an overflow is performed before the addition to ensure that no undefined behavior occurs. The value in result is only valid when the function returns false.

Further information: https://wiki.sei.cmu.edu/confluence/display/c/INT32-C.+Ensure+that+operations+on+signed+integers+do+not+result+in+overflow


The documentation for this struct was generated from the following file: