/// reduces code duplication in Sum() declarations below
template <typename T, typename U>
using AllUnsigned = typename std::conditional<
- std::is_unsigned<T>::value && std::is_unsigned<U>::value,
- std::true_type,
- std::false_type
- >::type;
+ std::is_unsigned<T>::value && std::is_unsigned<U>::value,
+ std::true_type,
+ std::false_type
+ >::type;
/// \returns a non-overflowing sum of the two unsigned arguments (or nothing)
template <typename T, typename U, EnableIfType<AllUnsigned<T,U>::value, int> = 0>
// tests below avoid undefined behavior of signed under/overflows
return b >= 0 ?
- ((a > std::numeric_limits<U>::max() - b) ? Optional<T>() : Optional<T>(a + b)):
- ((a < std::numeric_limits<U>::min() - b) ? Optional<T>() : Optional<T>(a + b));
+ ((a > std::numeric_limits<U>::max() - b) ? Optional<T>() : Optional<T>(a + b)):
+ ((a < std::numeric_limits<U>::min() - b) ? Optional<T>() : Optional<T>(a + b));
}
/// \returns a non-overflowing sum of the arguments (or nothing)