summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2021-09-20 23:39:24 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-09-21 00:50:11 +0000
commite07873f67e32ffeea460bfdaab03a9d0e9567847 (patch)
treee5ec93bc1a0a6172eed869f860d90c0901f215ce
parent6ff19433eb6f8dba381c6736a364b1967ba43541 (diff)
downloadmongo-e07873f67e32ffeea460bfdaab03a9d0e9567847.tar.gz
SERVER-59908 simplify extendedFCVTable use
-rw-r--r--src/mongo/util/version/releases.h.tpl35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/mongo/util/version/releases.h.tpl b/src/mongo/util/version/releases.h.tpl
index 787494840cf..f006eed1ed1 100644
--- a/src/mongo/util/version/releases.h.tpl
+++ b/src/mongo/util/version/releases.h.tpl
@@ -223,21 +223,24 @@ inline constexpr std::array extendedFCVTable {
#end for
};
+constexpr decltype(auto) findExtended(FeatureCompatibilityVersion v) {
+ return extendedFCVTable[static_cast<size_t>(v)];
+}
+
+constexpr StringData toString(FeatureCompatibilityVersion v) {
+ return findExtended(v).second;
+}
+
/**
- * A table with mappings between FeatureCompatibilityVersion::kVersion_X_Y and a pointer to the
- * "X.Y"_sd generated by the extended table. Thus, this a subset of the extended table.
+ * Pointers to nodes of the extended table that represent numbered software versions.
+ * Other FCV enum members, such as those representing transitions, are excluded.
*/
inline constexpr std::array standardFCVTable {
#for fcv, _ in filter(lambda p: p not in transition_fcvs, fcv_list):
- std::pair{FeatureCompatibilityVersion::$fcv,
- &extendedFCVTable[static_cast<size_t>(FeatureCompatibilityVersion::$fcv)].second},
+ &findExtended(FeatureCompatibilityVersion::$fcv),
#end for
};
-constexpr StringData toString(FeatureCompatibilityVersion v) {
- return extendedFCVTable[static_cast<size_t>(v)].second;
-}
-
/**
* Parses 'versionString', of the form "X.Y", to its corresponding FCV enum. For example, "5.1"
* will be parsed as FeatureCompatibilityVersion::$fcv_cpp_name(Version("5.1")).
@@ -245,11 +248,9 @@ constexpr StringData toString(FeatureCompatibilityVersion v) {
* enum.
*/
inline FeatureCompatibilityVersion parseVersionForFeatureFlags(StringData versionString) {
- for (const auto& [fcv, record] : standardFCVTable) {
- if (*record == versionString)
- return fcv;
- }
-
+ for (auto ptr : standardFCVTable)
+ if (ptr->second == versionString)
+ return ptr->first;
uasserted(ErrorCodes::BadValue,
fmt::format("Invalid FCV version {} for feature flag.", versionString));
}
@@ -259,12 +260,10 @@ inline FeatureCompatibilityVersion parseVersionForFeatureFlags(StringData versio
* version of the form 'X.Y'. Non-standard enums are transition enums, 'kInvalid' and
* 'kUnsetDefaultLastLTSBehavior'.
*/
-inline bool isStandardFCV(FeatureCompatibilityVersion v) {
- for (const auto& [fcv, record] : standardFCVTable) {
- if (v == fcv)
+constexpr bool isStandardFCV(FeatureCompatibilityVersion v) {
+ for (auto ptr : standardFCVTable)
+ if (ptr->first == v)
return true;
- }
-
return false;
}