[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 7566ae5 3/7: Prefer overloading to "magical"
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 7566ae5 3/7: Prefer overloading to "magical" default argument values |
Date: |
Sat, 11 May 2019 13:26:23 -0400 (EDT) |
branch: master
commit 7566ae55f5ec37ba84c60a8057fceea1dcfef4dd
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Prefer overloading to "magical" default argument values
---
cso_table.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++------------
cso_table.hpp | 12 ++++++++--
2 files changed, 68 insertions(+), 17 deletions(-)
diff --git a/cso_table.cpp b/cso_table.cpp
index 73f8c28..0ac73dd 100644
--- a/cso_table.cpp
+++ b/cso_table.cpp
@@ -916,8 +916,36 @@ static double const
q2017[cso_n_alb_or_anb][cso_n_gender][cso_n_smoking][cso_ome
},
};
+namespace
+{
+int get_sns_age(oenum_cso_era cso_era, mcenum_smoking smoking)
+{
+ return
+ ((mce_unismoke == smoking) ? 0
+ :(oe_1980cso == cso_era) ? cso_sns_age_1980
+ :(oe_2001cso == cso_era) ? cso_sns_age_2001
+ :(oe_2017cso == cso_era) ? cso_sns_age_2017
+ : throw "invalid cso sns age"
+ );
+}
+
+int get_omega(oenum_cso_era cso_era)
+{
+ return
+ ((oe_1980cso == cso_era) ? cso_omega_1980
+ :(oe_2001cso == cso_era) ? cso_omega_2001
+ :(oe_2017cso == cso_era) ? cso_omega_2017
+ : throw "invalid cso omega"
+ );
+}
+} // Unnamed namespace.
+
/// Return a single CSO ultimate table.
///
+/// This overload returns a [min_age, max_age] subset of a full
+/// valuation table that has been padded if necessary to provide
+/// values for all ages from zero to omega.
+///
/// Only the 1980, 2001, and 2017 eras are supported.
///
/// CSO tables are either ANB or ALB; they disregard other nuances of
@@ -952,26 +980,15 @@ std::vector<double> cso_table
:(oe_2017cso == cso_era) ? q2017[is_anb][gender][smoking]
: throw "invalid cso era"
);
- int const sns_age =
- ((mce_unismoke == smoking) ? 0
- :(oe_1980cso == cso_era) ? cso_sns_age_1980
- :(oe_2001cso == cso_era) ? cso_sns_age_2001
- :(oe_2017cso == cso_era) ? cso_sns_age_2017
- : throw "invalid cso sns age"
- );
- int const omega =
- ((oe_1980cso == cso_era) ? cso_omega_1980
- :(oe_2001cso == cso_era) ? cso_omega_2001
- :(oe_2017cso == cso_era) ? cso_omega_2017
- : throw "invalid cso omega"
- );
+ int const sns_age = get_sns_age(cso_era, smoking);
+ int const omega = get_omega (cso_era );
LMI_ASSERT(each_equal(p, p + sns_age, 0.0));
LMI_ASSERT(0 == std::count(p + sns_age, p + omega, 0.0));
LMI_ASSERT(1.0 == p[omega - 1]);
- if(-1 == min_age) min_age = sns_age;
- if(-1 == max_age) max_age = omega;
+ LMI_ASSERT(0 <= min_age);
+ LMI_ASSERT(max_age <= omega);
std::vector<double> v(p + min_age, p + max_age);
@@ -1001,3 +1018,29 @@ std::vector<double> cso_table
return v;
}
+
+/// Return a single CSO ultimate table.
+///
+/// This overload returns a full valuation table including all ages
+/// from zero (padded if necessary) to omega.
+///
+/// See the overload with more arguments for details.
+
+std::vector<double> cso_table
+ (oenum_cso_era cso_era
+ ,oenum_autopisty autopisty
+ ,oenum_alb_or_anb alb_or_anb
+ ,mcenum_gender gender
+ ,mcenum_smoking smoking
+ )
+{
+ return cso_table
+ (cso_era
+ ,autopisty
+ ,alb_or_anb
+ ,gender
+ ,smoking
+ ,get_sns_age(cso_era, smoking)
+ ,get_omega (cso_era )
+ );
+}
diff --git a/cso_table.hpp b/cso_table.hpp
index 2e69f34..5999ecb 100644
--- a/cso_table.hpp
+++ b/cso_table.hpp
@@ -36,8 +36,16 @@ std::vector<double> LMI_SO cso_table
,oenum_alb_or_anb
,mcenum_gender
,mcenum_smoking
- ,int min_age = -1
- ,int max_age = -1
+ ,int min_age
+ ,int max_age
+ );
+
+std::vector<double> LMI_SO cso_table
+ (oenum_cso_era
+ ,oenum_autopisty
+ ,oenum_alb_or_anb
+ ,mcenum_gender
+ ,mcenum_smoking
);
#endif // cso_table_hpp
- [lmi-commits] [lmi] master updated (30f5cff -> fe191f3), Greg Chicares, 2019/05/11
- [lmi-commits] [lmi] master 49d083a 5/7: Upgrade to gcc-8.x, Greg Chicares, 2019/05/11
- [lmi-commits] [lmi] master 09d67a8 4/7: Calculate 7PP and CVAT corridor from first principles, Greg Chicares, 2019/05/11
- [lmi-commits] [lmi] master fe191f3 7/7: Fully reflect earlier eradication of cygwin "MinGW_" mount, Greg Chicares, 2019/05/11
- [lmi-commits] [lmi] master bc0c833 6/7: Install bsdtar in chroot, Greg Chicares, 2019/05/11
- [lmi-commits] [lmi] master 7566ae5 3/7: Prefer overloading to "magical" default argument values,
Greg Chicares <=
- [lmi-commits] [lmi] master 19c01d9 2/7: Add minimum- and maximum-age arguments to cso_table(), Greg Chicares, 2019/05/11
- [lmi-commits] [lmi] master ac642ae 1/7: Simplify an assertion, Greg Chicares, 2019/05/11