Skip to content

Commit 08fcae6

Browse files
committed
Math: Refactored compile time type check in minnan/maxnan to give a meaningful error message.
1 parent 0b82f60 commit 08fcae6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/inet/common/INETMath.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ inline double n_choose_k(int n, int k) {
225225
* For example, the minimum of NaN and 1 must be NaN independently of the argument order.
226226
* See 'Not a number' section at https://2pi.dk/2016/05/ieee-min-max
227227
*/
228-
template<typename T, class = typename std::enable_if<!std::is_integral<T>::value>::type>
228+
template<typename T>
229229
inline const T minnan(const T& a, const T& b) {
230+
static_assert(!std::is_integral<T>::value, "minnan() is only meant for doubles and double based units, use std::min() for integers");
230231
if (a < b)
231232
return a;
232233
else if (b < a)
@@ -242,8 +243,9 @@ inline const T minnan(const T& a, const T& b) {
242243
* For example, the maximum of NaN and 1 must be NaN independently of the argument order.
243244
* See 'Not a number' section at https://2pi.dk/2016/05/ieee-min-max
244245
*/
245-
template<typename T, class = typename std::enable_if<!std::is_integral<T>::value>::type>
246+
template<typename T>
246247
inline const T maxnan(const T& a, const T& b) {
248+
static_assert(!std::is_integral<T>::value, "maxnan() is only meant for doubles and double based units, use std::max() for integers");
247249
if (a > b)
248250
return a;
249251
else if (b > a)

0 commit comments

Comments
 (0)