From 79be955d28c4e81358cc61f0b27f522c1b149a35 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 15 Jan 2015 14:06:17 +1100 Subject: [PATCH] maths: allow mixed type variadic min/max --- maths.hpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/maths.hpp b/maths.hpp index 9293fbcd..71ae5577 100644 --- a/maths.hpp +++ b/maths.hpp @@ -176,9 +176,15 @@ min (const T a) template -constexpr typename std::common_type::type -min (const T a , const U b , const Args &...args ) - { return min ( b < a ? b : a, args...); } +constexpr typename std::enable_if< + std::is_unsigned::type>::value == std::is_unsigned::type>::value && + std::is_integral::type>::value == std::is_integral::type>::value, + typename std::common_type::type +>::type +min (const T a, const U b, Args ...args) +{ + return min (a < b ? a : b, std::forward (args)...); +} //----------------------------------------------------------------------------- @@ -189,11 +195,16 @@ max (const T a) { return a; } -template -constexpr T -max (const T a , const T b , const Args &...args ) - { return max ( b > a ? b : a, args...); } - +template +constexpr typename std::enable_if< + std::is_unsigned::type>::value == std::is_unsigned::type>::value && + std::is_integral::type>::value == std::is_integral::type>::value, + typename std::common_type::type +>::type +max (const T a, const U b, Args ...args) +{ + return max (a > b ? a : b, std::forward (args)...); +} //----------------------------------------------------------------------------- template