diff options
author | Alex Turbov <i.zaufi@gmail.com> | 2021-07-30 00:49:56 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-08-20 13:35:12 (GMT) |
commit | 5469c71a824880eb646a0003cb001c58f24f9cce (patch) | |
tree | 819721bd7f935d2ace0cdf211bc5aac71b08e0f1 /Source/cmCMakeHostSystemInformationCommand.cxx | |
parent | 6c92f80f2ecb106916534d4b88704432476b9006 (diff) | |
download | CMake-5469c71a824880eb646a0003cb001c58f24f9cce.zip CMake-5469c71a824880eb646a0003cb001c58f24f9cce.tar.gz CMake-5469c71a824880eb646a0003cb001c58f24f9cce.tar.bz2 |
Refactor: Simplify `GetValue()` function calls
Diffstat (limited to 'Source/cmCMakeHostSystemInformationCommand.cxx')
-rw-r--r-- | Source/cmCMakeHostSystemInformationCommand.cxx | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/Source/cmCMakeHostSystemInformationCommand.cxx b/Source/cmCMakeHostSystemInformationCommand.cxx index 1464220..b2c4534 100644 --- a/Source/cmCMakeHostSystemInformationCommand.cxx +++ b/Source/cmCMakeHostSystemInformationCommand.cxx @@ -439,6 +439,21 @@ cm::optional<std::string> GetValue(cmExecutionStatus& status, return {}; } #endif + +cm::optional<std::string> GetValueChained() +{ + return {}; +} + +template <typename GetterFn, typename... Next> +cm::optional<std::string> GetValueChained(GetterFn current, Next... chain) +{ + auto value = current(); + if (value.has_value()) { + return value; + } + return GetValueChained(chain...); +} // END Private functions } // anonymous namespace @@ -475,24 +490,21 @@ bool cmCMakeHostSystemInformationCommand(std::vector<std::string> const& args, result_list += DELIM[!result_list.empty()]; auto const& key = args[i]; - auto value = GetValue(info, key); - if (!value) { + // clang-format off + auto value = + GetValueChained( + [&]() { return GetValue(info, key); } +#ifdef __linux__ + , [&]() { return GetValue(status, key, variable); } +#endif #ifdef HAVE_VS_SETUP_HELPER - value = GetValue(status, key); - if (!value) { - status.SetError("does not recognize <key> " + key); - return false; - } -#elif defined(__linux__) - value = GetValue(status, key, variable); - if (!value) { - status.SetError("does not recognize <key> " + key); - return false; - } -#else + , [&]() { return GetValue(status, key); } +#endif + ); + // clang-format on + if (!value) { status.SetError("does not recognize <key> " + key); return false; -#endif } result_list += value.value(); } |