summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-08-23 13:27:19 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-08-23 13:27:19 +0200
commitb30fbd10720959bf16835891a2a802b38a1717bf (patch)
tree428814057c1a04bfabd2a7eb14483f6844c70f16 /compat
parent7df3e936e1db5a23aa0bef804eec0e0af5f4ab65 (diff)
compat/util: move typical "clamp" function here
Diffstat (limited to 'compat')
-rw-r--r--compat/util.hpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/compat/util.hpp b/compat/util.hpp
index 33e64a80..453d94bd 100644
--- a/compat/util.hpp
+++ b/compat/util.hpp
@@ -46,6 +46,16 @@ public:
inhibit_qt_signals(std::shared_ptr<QObject> val) : inhibit_qt_signals(*val.get()) {}
};
+template<typename t, typename u, typename w>
+auto clamp(t val, u min, w max) -> decltype (val * min * max)
+{
+ if (val > max)
+ return max;
+ if (val < min)
+ return min;
+ return val;
+}
+
namespace detail {
template<typename t>