diff --git a/Source/cmCommandLineArgument.h b/Source/cmCommandLineArgument.h index 72ab0450fd..33c91bc5a3 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 {