[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 7d2794b 7/7: Use minmax<T> iff std::numeric_l
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 7d2794b 7/7: Use minmax<T> iff std::numeric_limits<T>::is_bounded |
Date: |
Sat, 6 Mar 2021 17:55:55 -0500 (EST) |
branch: master
commit 7d2794bbe36982ce51345f5b82fb68df58b9ad0f
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Use minmax<T> iff std::numeric_limits<T>::is_bounded
Class template minmax<T> uses std::numeric_limits<T>::lowest() and
std::numeric_limits<T>::max(), which are "meaningful" iff
std::numeric_limits<T>::lowest().
* miscellany.hpp: Assert "meaningfulness" accordingly.
* input_realization.cpp: Use std::minmax_element() directly instead,
which is much simpler than specializing std::numeric_limits for
class template tn_range.
---
input_realization.cpp | 38 +++++++++++++++++++++++++-------------
miscellany.hpp | 2 ++
2 files changed, 27 insertions(+), 13 deletions(-)
diff --git a/input_realization.cpp b/input_realization.cpp
index 45a67e6..35a8829 100644
--- a/input_realization.cpp
+++ b/input_realization.cpp
@@ -32,7 +32,7 @@
#include "global_settings.hpp"
#include "handle_exceptions.hpp" // report_exception()
#include "input_sequence_aux.hpp" // convert_vector()
-#include "miscellany.hpp" // each_equal(), minmax
+#include "miscellany.hpp" // each_equal()
#include "round_to.hpp"
#include "ssize_lmi.hpp"
#include "value_cast.hpp"
@@ -418,15 +418,19 @@ std::string Input::RealizeCashValueEnhancementRate()
// SOMEDAY !! If we add a production like
// numeric-value: numeric-literal %
// then we might say "between 0% and 100%." here.
- minmax<tnr_unrestricted_double> extrema(CashValueEnhancementRateRealized_);
- if(!(0.0 <= extrema.minimum().value() && extrema.maximum().value() <= 1.0))
+ LMI_ASSERT(!CashValueEnhancementRateRealized_.empty());
+ auto const extrema = std::minmax_element
+ (CashValueEnhancementRateRealized_.begin()
+ ,CashValueEnhancementRateRealized_.end()
+ );
+ if(!(0.0 <= (*extrema.first).value() && (*extrema.second).value() <= 1.0))
{
std::ostringstream oss;
oss
<< "Cash value enhancement rate as entered ranges from "
- << extrema.minimum()
+ << *extrema.first
<< " to "
- << extrema.maximum()
+ << *extrema.second
<< ", but must be between 0 and 1 inclusive."
;
return oss.str();
@@ -451,15 +455,19 @@ std::string Input::RealizeCorporationTaxBracket()
// SOMEDAY !! If we add a production like
// numeric-value: numeric-literal %
// then we might say "between 0% and 100%." here.
- minmax<tnr_unrestricted_double> extrema(CorporationTaxBracketRealized_);
- if(!(0.0 <= extrema.minimum().value() && extrema.maximum().value() <= 1.0))
+ LMI_ASSERT(!CorporationTaxBracketRealized_.empty());
+ auto const extrema = std::minmax_element
+ (CorporationTaxBracketRealized_.begin()
+ ,CorporationTaxBracketRealized_.end()
+ );
+ if(!(0.0 <= (*extrema.first).value() && (*extrema.second).value() <= 1.0))
{
std::ostringstream oss;
oss
<< "Corporate tax bracket as entered ranges from "
- << extrema.minimum()
+ << *extrema.first
<< " to "
- << extrema.maximum()
+ << *extrema.second
<< ", but must be between 0 and 1 inclusive."
;
return oss.str();
@@ -484,15 +492,19 @@ std::string Input::RealizeTaxBracket()
// SOMEDAY !! If we add a production like
// numeric-value: numeric-literal %
// then we might say "between 0% and 100%." here.
- minmax<tnr_unrestricted_double> extrema(TaxBracketRealized_);
- if(!(0.0 <= extrema.minimum().value() && extrema.maximum().value() <= 1.0))
+ LMI_ASSERT(!TaxBracketRealized_.empty());
+ auto const extrema = std::minmax_element
+ (TaxBracketRealized_.begin()
+ ,TaxBracketRealized_.end()
+ );
+ if(!(0.0 <= (*extrema.first).value() && (*extrema.second).value() <= 1.0))
{
std::ostringstream oss;
oss
<< "Individual tax bracket as entered ranges from "
- << extrema.minimum()
+ << *extrema.first
<< " to "
- << extrema.maximum()
+ << *extrema.second
<< ", but must be between 0 and 1 inclusive."
;
return oss.str();
diff --git a/miscellany.hpp b/miscellany.hpp
index 3decf62..56c5e64 100644
--- a/miscellany.hpp
+++ b/miscellany.hpp
@@ -94,6 +94,8 @@ std::string floating_rep(T t)
template<typename T>
class minmax
{
+ static_assert(std::numeric_limits<T>::is_bounded);
+
public:
minmax() {}
- [lmi-commits] [lmi] master updated (27b708a -> 7d2794b), Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master 869de45 4/7: Fix defect introduced 20180319T1957Z: min() isn't lowest(), Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master 7d2794b 7/7: Use minmax<T> iff std::numeric_limits<T>::is_bounded,
Greg Chicares <=
- [lmi-commits] [lmi] master 5004bd4 5/7: Define 'minmax' of an empty vector, Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master e23c058 6/7: Prefer data-member initializers to ctor delegation, Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master 24611b1 1/7: Improve a unit test, Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master 8e69f1d 2/7: Don't write lowest() as "min()" without asserting they're the same, Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master 3330a9a 3/7: Don't write lowest() as "min()" even it they're the same, Greg Chicares, 2021/03/06