Skip to content
Snippets Groups Projects
Commit 5406f1a8 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

make max and min work with user-defined casts

parent 73513f33
No related branches found
No related tags found
1 merge request!35make max and min work with user-defined casts
...@@ -43,7 +43,8 @@ namespace AMDiS ...@@ -43,7 +43,8 @@ namespace AMDiS
template <class T0, class T1> template <class T0, class T1>
constexpr auto min(T0 a, T1 b) 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> template <class T0>
...@@ -62,12 +63,14 @@ namespace AMDiS ...@@ -62,12 +63,14 @@ namespace AMDiS
/// Implementation of the maximum of values \f$ max(a,b)\f$ of any type /// 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> template <class T0, class T1>
constexpr auto max(T0 a, T1 b) 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> template <class T0>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment