maths: allow mixed type variadic min/max

This commit is contained in:
Danny Robson 2015-01-15 14:06:17 +11:00
parent 21725e9b99
commit 79be955d28

View File

@ -176,9 +176,15 @@ min (const T a)
template <typename T, typename U, typename ...Args> template <typename T, typename U, typename ...Args>
constexpr typename std::common_type<T, U>::type constexpr typename std::enable_if<
min (const T a , const U b , const Args &...args ) std::is_unsigned<typename std::decay<T>::type>::value == std::is_unsigned<typename std::decay<U>::type>::value &&
{ return min ( b < a ? b : a, args...); } std::is_integral<typename std::decay<T>::type>::value == std::is_integral<typename std::decay<U>::type>::value,
typename std::common_type<T,U>::type
>::type
min (const T a, const U b, Args ...args)
{
return min (a < b ? a : b, std::forward<Args> (args)...);
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -189,11 +195,16 @@ max (const T a)
{ return a; } { return a; }
template <typename T, typename ...Args> template <typename T, typename U, typename ...Args>
constexpr T constexpr typename std::enable_if<
max (const T a , const T b , const Args &...args ) std::is_unsigned<typename std::decay<T>::type>::value == std::is_unsigned<typename std::decay<U>::type>::value &&
{ return max ( b > a ? b : a, args...); } std::is_integral<typename std::decay<T>::type>::value == std::is_integral<typename std::decay<U>::type>::value,
typename std::common_type<T,U>::type
>::type
max (const T a, const U b, Args ...args)
{
return max (a > b ? a : b, std::forward<Args> (args)...);
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T> template <typename T>