From 5406f1a8156cd1bde0924fb2c994f1557d409f32 Mon Sep 17 00:00:00 2001 From: Simon Praetorius <simon.praetorius@tu-dresden.de> Date: Thu, 25 Apr 2019 17:31:49 +0200 Subject: [PATCH] make max and min work with user-defined casts --- src/amdis/common/Math.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/amdis/common/Math.hpp b/src/amdis/common/Math.hpp index c01d0d97..efb2ceb3 100644 --- a/src/amdis/common/Math.hpp +++ b/src/amdis/common/Math.hpp @@ -43,7 +43,8 @@ namespace AMDiS template <class T0, class T1> constexpr auto min(T0 a, T1 b) { - return a < b ? a : b; + using T = std::conditional_t<(sizeof(T0)>sizeof(T1)),T0,T1>; + return a < b ? T(a) : T(b); } template <class T0> @@ -62,12 +63,14 @@ namespace AMDiS /// Implementation of the maximum of values \f$ max(a,b)\f$ of any type - /// supporting the `>` relation. + /// supporting the `<` relation. /// @{ + template <class T0, class T1> constexpr auto max(T0 a, T1 b) { - return a < b ? b : a; + using T = std::conditional_t<(sizeof(T0)>sizeof(T1)),T0,T1>; + return a < b ? T(b) : T(a); } template <class T0> -- GitLab