diff --git a/Source/cmArgumentParser.h b/Source/cmArgumentParser.h index fdf54fbd45..b35d7f3bc8 100644 --- a/Source/cmArgumentParser.h +++ b/Source/cmArgumentParser.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -176,6 +177,17 @@ public: void Bind(MaybeEmpty>& val); void Bind(NonEmpty>& val); void Bind(std::vector>& val); + template + void Bind(NonEmpty>>& val, + U const& context) + { + this->Bind( + [&val, &context](cm::string_view arg) -> Continue { + val.emplace_back(std::string(arg), context); + return Continue::Yes; + }, + ExpectAtLeast{ 1 }); + } // cm::optional<> records the presence the keyword to which it binds. template @@ -187,6 +199,15 @@ public: this->Bind(*optVal); } + template + void Bind(cm::optional& optVal, U const& context) + { + if (!optVal) { + optVal.emplace(); + } + this->Bind(*optVal, context); + } + template void Parse(Range const& args, std::size_t pos = 0) { @@ -232,6 +253,17 @@ public: return *this; } + template + cmArgumentParser& BindWithContext(cm::static_string_view name, + T Result::*member, U Result::*context) + { + this->Base::Bind(name, [member, context](Instance& instance) { + auto* result = static_cast(instance.Result); + instance.Bind(result->*member, result->*context); + }); + return *this; + } + cmArgumentParser& Bind(cm::static_string_view name, Continue (Result::*member)(cm::string_view), ExpectAtLeast expect = { 1 })