diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2021-09-26 20:56:25 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2021-09-26 21:10:13 +0200 |
commit | d4d799cac8080d4066394f338c31611ae655d5f6 (patch) | |
tree | ff37ab02c0bc8aaf30f44ad4c217527df74a774f /compat/math.hpp | |
parent | cecd3f8a89693c5722b5e52baebb58edaef1a91c (diff) |
compat: use std::clamp, remove own version
Diffstat (limited to 'compat/math.hpp')
-rw-r--r-- | compat/math.hpp | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/compat/math.hpp b/compat/math.hpp index 34428cbd..1387324e 100644 --- a/compat/math.hpp +++ b/compat/math.hpp @@ -5,54 +5,6 @@ #include <cmath> #include <type_traits> -namespace util_detail { - -template<typename n> -inline auto clamp_float(n val, n min_, n max_) -{ - return std::fmin(std::fmax(val, min_), max_); -} - -template<typename t> -struct clamp final -{ - static inline auto clamp_(t val, t min_, t max_) - { - if (unlikely(val > max_)) - return max_; - if (unlikely(val < min_)) - return min_; - return val; - } -}; - -template<> -struct clamp<float> -{ - static inline auto clamp_(float val, float min_, float max_) - { - return clamp_float(val, min_, max_); - } -}; - -template<> -struct clamp<double> -{ - static inline auto clamp_(double val, double min_, double max_) - { - return clamp_float(val, min_, max_); - } -}; - -} // ns util_detail - -template<typename t, typename u, typename v> -inline auto clamp(const t& val, const u& min, const v& max) -{ - using w = cv_qualified<decltype(val + min + max)>; - return util_detail::clamp<w>::clamp_(val, min, max); -} - template<typename t> inline auto iround(t val) -> std::enable_if_t<std::is_floating_point_v<remove_cvref_t<t>>, int> { |