[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 2deff71 3/4: Use identity element for std::ma
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 2deff71 3/4: Use identity element for std::max() and std::min() in class minmax |
Date: |
Sun, 7 Mar 2021 15:05:41 -0500 (EST) |
branch: master
commit 2deff717e01294ee2bb6e07c2693a90a3720ad70
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Use identity element for std::max() and std::min() in class minmax
---
miscellany.hpp | 4 ++--
miscellany_test.cpp | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/miscellany.hpp b/miscellany.hpp
index f101e5a..b72439f 100644
--- a/miscellany.hpp
+++ b/miscellany.hpp
@@ -143,8 +143,8 @@ class minmax
T maximum() const {return maximum_;}
private:
- T minimum_ {std::numeric_limits<T>::max()};
- T maximum_ {std::numeric_limits<T>::lowest()};
+ T minimum_ {supremum<T>()};
+ T maximum_ {infimum <T>()};
};
template<typename T> bool operator< (T t, minmax<T> m) {return t <
m.minimum();}
diff --git a/miscellany_test.cpp b/miscellany_test.cpp
index 6c68916..83d68d5 100644
--- a/miscellany_test.cpp
+++ b/miscellany_test.cpp
@@ -155,8 +155,8 @@ void test_minmax()
// Test default ctor.
minmax<double> const dbl_minmax {};
- LMI_TEST_EQUAL( DBL_MAX, dbl_minmax.minimum());
- LMI_TEST_EQUAL(-DBL_MAX, dbl_minmax.maximum());
+ LMI_TEST_EQUAL( HUGE_VAL, dbl_minmax.minimum());
+ LMI_TEST_EQUAL(-HUGE_VAL, dbl_minmax.maximum());
// Test explicit ctor with zero-element argument.
std::vector<int> const empty_vector {};