diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2022-04-15 19:17:05 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2022-04-18 20:22:39 (GMT) |
commit | 0645d08c98a94e69027727468e55938d4e095fba (patch) | |
tree | 211b184c9761d998a2c9e841814e3ccfa85bef07 /Source/cmCommandLineArgument.h | |
parent | 6453bd046ef23798c64333042d76851f15eff2fc (diff) | |
download | CMake-0645d08c98a94e69027727468e55938d4e095fba.zip CMake-0645d08c98a94e69027727468e55938d4e095fba.tar.gz CMake-0645d08c98a94e69027727468e55938d4e095fba.tar.bz2 |
cmCommandLineArgument: Add setToTrue() and setToValue() helpers
Diffstat (limited to 'Source/cmCommandLineArgument.h')
-rw-r--r-- | Source/cmCommandLineArgument.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Source/cmCommandLineArgument.h b/Source/cmCommandLineArgument.h index 72ab045..33c91bc 100644 --- a/Source/cmCommandLineArgument.h +++ b/Source/cmCommandLineArgument.h @@ -201,7 +201,57 @@ struct cmCommandLineArgument return (parseState == ParseMode::Valid); } + template <typename... Values> + static std::function<FunctionSignature> setToTrue(Values&&... values) + { + return ArgumentLambdaHelper<FunctionSignature>::generateSetToTrue( + std::forward<Values>(values)...); + } + + template <typename... Values> + static std::function<FunctionSignature> setToValue(Values&&... values) + { + return ArgumentLambdaHelper<FunctionSignature>::generateSetToValue( + std::forward<Values>(values)...); + } + private: + template <typename T> + class ArgumentLambdaHelper; + + template <typename... CallState> + class ArgumentLambdaHelper<bool(const std::string&, CallState...)> + { + public: + static std::function<bool(const std::string&, CallState...)> + generateSetToTrue(bool& value1) + { + return [&value1](const std::string&, CallState&&...) -> bool { + value1 = true; + return true; + }; + } + + static std::function<bool(const std::string&, CallState...)> + generateSetToTrue(bool& value1, bool& value2) + { + return [&value1, &value2](const std::string&, CallState&&...) -> bool { + value1 = true; + value2 = true; + return true; + }; + } + + static std::function<bool(const std::string&, CallState...)> + generateSetToValue(std::string& value1) + { + return [&value1](const std::string& arg, CallState&&...) -> bool { + value1 = arg; + return true; + }; + } + }; + std::string extract_single_value(std::string const& input, ParseMode& parseState) const { |