diff --git a/Source/cmArgumentParser.cxx b/Source/cmArgumentParser.cxx index 765e9cb88c..b2d55573de 100644 --- a/Source/cmArgumentParser.cxx +++ b/Source/cmArgumentParser.cxx @@ -72,6 +72,16 @@ void Instance::Bind(std::string& val) ExpectAtLeast{ 1 }); } +void Instance::Bind(MaybeEmpty& val) +{ + this->Bind( + [&val](cm::string_view arg) -> Continue { + val = std::string(arg); + return Continue::No; + }, + ExpectAtLeast{ 1 }); +} + void Instance::Bind(NonEmpty& val) { this->Bind( diff --git a/Source/cmArgumentParser.h b/Source/cmArgumentParser.h index 2b37869817..0628bb441d 100644 --- a/Source/cmArgumentParser.h +++ b/Source/cmArgumentParser.h @@ -212,6 +212,7 @@ public: void Bind(std::function f, ExpectAtLeast expect); void Bind(bool& val); void Bind(std::string& val); + void Bind(MaybeEmpty& val); void Bind(NonEmpty& val); void Bind(Maybe& val); void Bind(MaybeEmpty>& val); diff --git a/Source/cmArgumentParserTypes.h b/Source/cmArgumentParserTypes.h index bd14f9bd80..6ac71ca5cb 100644 --- a/Source/cmArgumentParserTypes.h +++ b/Source/cmArgumentParserTypes.h @@ -36,6 +36,12 @@ struct MaybeEmpty> : public std::vector using std::vector::vector; using std::vector::operator=; }; +template <> +struct MaybeEmpty : public std::string +{ + using std::string::basic_string; + using std::string::operator=; +}; template struct NonEmpty;