Przeglądaj źródła

cmArgumentParser: Propagate constructors through binding wrapper types

Brad King 3 lat temu
rodzic
commit
77fcb00a2b

+ 40 - 0
Source/cmArgumentParserTypes.h

@@ -4,21 +4,61 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
+#if defined(__SUNPRO_CC)
+
+#  include <string>
+#  include <vector>
+
+namespace ArgumentParser {
+
+template <typename T>
+struct Maybe;
+template <>
+struct Maybe<std::string> : public std::string
+{
+  using std::string::basic_string;
+};
+
+template <typename T>
+struct MaybeEmpty;
+template <typename T>
+struct MaybeEmpty<std::vector<T>> : public std::vector<T>
+{
+  using std::vector<T>::vector;
+};
+
+template <typename T>
+struct NonEmpty;
+template <typename T>
+struct NonEmpty<std::vector<T>> : public std::vector<T>
+{
+  using std::vector<T>::vector;
+};
+
+} // namespace ArgumentParser
+
+#else
+
 namespace ArgumentParser {
 
 template <typename T>
 struct Maybe : public T
 {
+  using T::T;
 };
 
 template <typename T>
 struct MaybeEmpty : public T
 {
+  using T::T;
 };
 
 template <typename T>
 struct NonEmpty : public T
 {
+  using T::T;
 };
 
 } // namespace ArgumentParser
+
+#endif

+ 14 - 0
Tests/CMakeLib/testArgumentParser.cxx

@@ -39,6 +39,15 @@ struct Result : public ArgumentParser::ParseResult
   cm::optional<std::vector<std::vector<std::string>>> Multi3;
   cm::optional<std::vector<std::vector<std::string>>> Multi4;
 
+  ArgumentParser::Maybe<std::string> UnboundMaybe{ 'u', 'n', 'b', 'o',
+                                                   'u', 'n', 'd' };
+  ArgumentParser::MaybeEmpty<std::vector<std::string>> UnboundMaybeEmpty{
+    1, "unbound"
+  };
+  ArgumentParser::NonEmpty<std::vector<std::string>> UnboundNonEmpty{
+    1, "unbound"
+  };
+
   std::vector<cm::string_view> ParsedKeywords;
 };
 
@@ -69,6 +78,7 @@ bool verifyResult(Result const& result,
 {
   static std::vector<std::string> const foobar = { "foo", "bar" };
   static std::vector<std::string> const barfoo = { "bar", "foo" };
+  static std::vector<std::string> const unbound = { "unbound" };
   static std::vector<cm::string_view> const parsedKeywords = {
     /* clang-format off */
     "OPTION_1",
@@ -133,6 +143,10 @@ bool verifyResult(Result const& result,
   ASSERT_TRUE(unparsedArguments.size() == 1);
   ASSERT_TRUE(unparsedArguments[0] == "bar");
 
+  ASSERT_TRUE(result.UnboundMaybe == "unbound");
+  ASSERT_TRUE(result.UnboundMaybeEmpty == unbound);
+  ASSERT_TRUE(result.UnboundNonEmpty == unbound);
+
   ASSERT_TRUE(result.ParsedKeywords == parsedKeywords);
 
   ASSERT_TRUE(result.GetKeywordErrors().size() == keywordErrors.size());