From 3f38f9511b23ca2e73ae20dff55b89b5b192e078 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 9 Dec 2025 13:25:32 -0500 Subject: [PATCH] cmArgumentParser: Add support for MaybeEmpty Add it for completeness, though it is the same as plain `std::string`. Also extend the SunPro/EDG workaround to cover this type. --- Source/cmArgumentParser.cxx | 10 ++++++++++ Source/cmArgumentParser.h | 1 + Source/cmArgumentParserTypes.h | 6 ++++++ 3 files changed, 17 insertions(+) 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;