diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-10-19 14:46:16 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-10-19 14:46:16 +0200 |
commit | e6a9c66a233a84bae5c6dba9ac531943f00fc97f (patch) | |
tree | 759e058970e6bcd88b8e543b26958c22434e1db2 /compat | |
parent | 3e8b619aa87157bdfe245ce2110809ead8649dfa (diff) |
compat/util: fix conversion from value<t> for clamp
Diffstat (limited to 'compat')
-rw-r--r-- | compat/util.hpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/compat/util.hpp b/compat/util.hpp index 20be92a4..abcc9ba2 100644 --- a/compat/util.hpp +++ b/compat/util.hpp @@ -23,8 +23,10 @@ void run_in_thread_async(QObject* obj, F&& fun) QObject::connect(&src, &QObject::destroyed, obj, std::move(fun), Qt::AutoConnection); } -template<typename t, typename u, typename w> -auto clamp(t val, u min, w max) -> decltype (val * min * max) +namespace detail { + +template<typename t, typename u, typename w, typename n> +inline auto clamp_(n val, n min, n max) -> n { if (val > max) return max; @@ -33,6 +35,14 @@ auto clamp(t val, u min, w max) -> decltype (val * min * max) return val; } +} + +template<typename t, typename u, typename w> +inline auto clamp(const t& val, const u& min, const w& max) -> decltype(val * min * max) +{ + return ::detail::clamp_<t, u, w, decltype(val * min * max)>(val, min, max); +} + namespace detail { template<typename t> |