Просмотр исходного кода

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.
Brad King 2 месяцев назад
Родитель
Сommit
3f38f9511b
3 измененных файлов с 17 добавлено и 0 удалено
  1. 10 0
      Source/cmArgumentParser.cxx
  2. 1 0
      Source/cmArgumentParser.h
  3. 6 0
      Source/cmArgumentParserTypes.h

+ 10 - 0
Source/cmArgumentParser.cxx

@@ -72,6 +72,16 @@ void Instance::Bind(std::string& val)
     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)
 {
   this->Bind(

+ 1 - 0
Source/cmArgumentParser.h

@@ -212,6 +212,7 @@ public:
   void Bind(std::function<Continue(cm::string_view)> f, ExpectAtLeast expect);
   void Bind(bool& val);
   void Bind(std::string& val);
+  void Bind(MaybeEmpty<std::string>& val);
   void Bind(NonEmpty<std::string>& val);
   void Bind(Maybe<std::string>& val);
   void Bind(MaybeEmpty<std::vector<std::string>>& val);

+ 6 - 0
Source/cmArgumentParserTypes.h

@@ -36,6 +36,12 @@ struct MaybeEmpty<std::vector<T>> : public std::vector<T>
   using std::vector<T>::vector;
   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>
 struct NonEmpty;