diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/o3tl/safeint.hxx | 30 |
1 files changed, 2 insertions, 28 deletions
diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx index 801b3dc6fdd5..85c61f8c33d3 100644 --- a/include/o3tl/safeint.hxx +++ b/include/o3tl/safeint.hxx @@ -27,9 +27,7 @@ namespace o3tl { -template<typename T> inline -typename std::enable_if<std::is_signed<T>::value, T>::type saturating_add( - T a, T b) +template <typename T> inline T saturating_add(T a, T b) { if (b >= 0) { if (a <= std::numeric_limits<T>::max() - b) { @@ -46,20 +44,7 @@ typename std::enable_if<std::is_signed<T>::value, T>::type saturating_add( } } -template<typename T> inline -typename std::enable_if<std::is_unsigned<T>::value, T>::type saturating_add( - T a, T b) -{ - if (a <= std::numeric_limits<T>::max() - b) { - return a + b; - } else { - return std::numeric_limits<T>::max(); - } -} - -template<typename T> inline -typename std::enable_if<std::is_signed<T>::value, T>::type saturating_sub( - T a, T b) +template <typename T> inline T saturating_sub(T a, T b) { if (b >= 0) { if (a >= std::numeric_limits<T>::min() + b) { @@ -77,17 +62,6 @@ typename std::enable_if<std::is_signed<T>::value, T>::type saturating_sub( } template<typename T> inline -typename std::enable_if<std::is_unsigned<T>::value, T>::type saturating_sub( - T a, T b) -{ - if (a >= std::numeric_limits<T>::min() + b) { - return a - b; - } else { - return std::numeric_limits<T>::min(); - } -} - -template<typename T> inline typename std::enable_if<std::is_signed<T>::value, T>::type saturating_toggle_sign( T a) { |