From 0645d08c98a94e69027727468e55938d4e095fba Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Fri, 15 Apr 2022 15:17:05 -0400 Subject: cmCommandLineArgument: Add setToTrue() and setToValue() helpers --- Source/cmCommandLineArgument.h | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) 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 + static std::function setToTrue(Values&&... values) + { + return ArgumentLambdaHelper::generateSetToTrue( + std::forward(values)...); + } + + template + static std::function setToValue(Values&&... values) + { + return ArgumentLambdaHelper::generateSetToValue( + std::forward(values)...); + } + private: + template + class ArgumentLambdaHelper; + + template + class ArgumentLambdaHelper + { + public: + static std::function + generateSetToTrue(bool& value1) + { + return [&value1](const std::string&, CallState&&...) -> bool { + value1 = true; + return true; + }; + } + + static std::function + generateSetToTrue(bool& value1, bool& value2) + { + return [&value1, &value2](const std::string&, CallState&&...) -> bool { + value1 = true; + value2 = true; + return true; + }; + } + + static std::function + 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 { -- cgit v0.12