cmArgumentParser: Add support for MaybeEmpty<std::string>

Add it for completeness, though it is the same as plain `std::string`.
Also extend the SunPro/EDG workaround to cover this type.
This commit is contained in:
Brad King
2025-12-09 13:25:32 -05:00
parent 1ec7201558
commit 3f38f9511b
3 changed files with 17 additions and 0 deletions
+10
View File
@@ -72,6 +72,16 @@ void Instance::Bind(std::string& val)
ExpectAtLeast{ 1 }); ExpectAtLeast{ 1 });
} }
void Instance::Bind(MaybeEmpty<std::string>& val)
{
this->Bind(
[&val](cm::string_view arg) -> Continue {
val = std::string(arg);
return Continue::No;
},
ExpectAtLeast{ 1 });
}
void Instance::Bind(NonEmpty<std::string>& val) void Instance::Bind(NonEmpty<std::string>& val)
{ {
this->Bind( this->Bind(
+1
View File
@@ -212,6 +212,7 @@ public:
void Bind(std::function<Continue(cm::string_view)> f, ExpectAtLeast expect); void Bind(std::function<Continue(cm::string_view)> f, ExpectAtLeast expect);
void Bind(bool& val); void Bind(bool& val);
void Bind(std::string& val); void Bind(std::string& val);
void Bind(MaybeEmpty<std::string>& val);
void Bind(NonEmpty<std::string>& val); void Bind(NonEmpty<std::string>& val);
void Bind(Maybe<std::string>& val); void Bind(Maybe<std::string>& val);
void Bind(MaybeEmpty<std::vector<std::string>>& val); void Bind(MaybeEmpty<std::vector<std::string>>& val);
+6
View File
@@ -36,6 +36,12 @@ struct MaybeEmpty<std::vector<T>> : public std::vector<T>
using std::vector<T>::vector; using std::vector<T>::vector;
using std::vector<T>::operator=; using std::vector<T>::operator=;
}; };
template <>
struct MaybeEmpty<std::string> : public std::string
{
using std::string::basic_string;
using std::string::operator=;
};
template <typename T> template <typename T>
struct NonEmpty; struct NonEmpty;