summaryrefslogtreecommitdiffstats
path: root/Source/cmArgumentParser.h
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-06-20 21:29:18 (GMT)
committerBrad King <brad.king@kitware.com>2022-07-05 20:35:01 (GMT)
commit0a4c5164c93a9c1c8ef7a8191fc46ca80f643168 (patch)
tree6d65039ec68b9fec27a4a7057ae03f44f9c48c59 /Source/cmArgumentParser.h
parentf3dbf4b89d4e74d30fae9e7696caef4158c707e5 (diff)
downloadCMake-0a4c5164c93a9c1c8ef7a8191fc46ca80f643168.zip
CMake-0a4c5164c93a9c1c8ef7a8191fc46ca80f643168.tar.gz
CMake-0a4c5164c93a9c1c8ef7a8191fc46ca80f643168.tar.bz2
cmArgumentParser: Offer cm::optional bindings to capture keyword presence
Several clients have been using `keywordsMissingValue` or `parsedKeywords` to check for the presence of keywords. Offer them a type-encoded way to explicitly check whether a keyword is present.
Diffstat (limited to 'Source/cmArgumentParser.h')
-rw-r--r--Source/cmArgumentParser.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/Source/cmArgumentParser.h b/Source/cmArgumentParser.h
index 2120a27..8be5a9c 100644
--- a/Source/cmArgumentParser.h
+++ b/Source/cmArgumentParser.h
@@ -10,6 +10,7 @@
#include <utility>
#include <vector>
+#include <cm/optional>
#include <cm/string_view>
#include <cmext/string_view>
@@ -39,6 +40,16 @@ public:
void Bind(std::vector<std::string>& val);
void Bind(std::vector<std::vector<std::string>>& val);
+ // cm::optional<> records the presence the keyword to which it binds.
+ template <typename T>
+ void Bind(cm::optional<T>& optVal)
+ {
+ if (!optVal) {
+ optVal.emplace();
+ }
+ this->Bind(*optVal);
+ }
+
void Consume(cm::string_view arg, void* result,
std::vector<std::string>* unparsedArguments,
std::vector<cm::string_view>* keywordsMissingValue,