From b30fbd10720959bf16835891a2a802b38a1717bf Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 23 Aug 2016 13:27:19 +0200 Subject: compat/util: move typical "clamp" function here --- compat/util.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'compat') 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 val) : inhibit_qt_signals(*val.get()) {} }; +template +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 -- cgit v1.2.3