diff options
Diffstat (limited to 'include/o3tl/strong_int.hxx')
-rw-r--r-- | include/o3tl/strong_int.hxx | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/include/o3tl/strong_int.hxx b/include/o3tl/strong_int.hxx index 8a9d91dbfb8c..738d30f01a8b 100644 --- a/include/o3tl/strong_int.hxx +++ b/include/o3tl/strong_int.hxx @@ -36,33 +36,37 @@ template<typename T1, typename T2> constexpr typename std::enable_if< std::is_signed<T1>::value && std::is_signed<T2>::value, bool>::type isInRange(T2 value) { - return value >= std::numeric_limits<T1>::min() - && value <= std::numeric_limits<T1>::max(); + const bool ret = value >= std::numeric_limits<T1>::min() + && value <= std::numeric_limits<T1>::max(); + return ret; } template<typename T1, typename T2> constexpr typename std::enable_if< std::is_signed<T1>::value && std::is_unsigned<T2>::value, bool>::type isInRange(T2 value) { - return value + const bool ret = value <= static_cast<typename std::make_unsigned<T1>::type>( std::numeric_limits<T1>::max()); + return ret; } template<typename T1, typename T2> constexpr typename std::enable_if< std::is_unsigned<T1>::value && std::is_signed<T2>::value, bool>::type isInRange(T2 value) { - return value >= 0 + const bool ret = value >= 0 && (static_cast<typename std::make_unsigned<T2>::type>(value) <= std::numeric_limits<T1>::max()); + return ret; } template<typename T1, typename T2> constexpr typename std::enable_if< std::is_unsigned<T1>::value && std::is_unsigned<T2>::value, bool>::type isInRange(T2 value) { - return value <= std::numeric_limits<T1>::max(); + const bool ret = value <= std::numeric_limits<T1>::max(); + return ret; } } |