diff options
author | Brad King <brad.king@kitware.com> | 2022-07-26 18:03:32 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-07-27 11:03:31 (GMT) |
commit | 77fcb00a2b76518c0db861a96a8f4857a50b140e (patch) | |
tree | 114e4ae50d6f1679f6ef0344bd4d1d70e371ffc7 | |
parent | 5fc4e121a18d9e403f1541348c2889e9bc153791 (diff) | |
download | CMake-77fcb00a2b76518c0db861a96a8f4857a50b140e.zip CMake-77fcb00a2b76518c0db861a96a8f4857a50b140e.tar.gz CMake-77fcb00a2b76518c0db861a96a8f4857a50b140e.tar.bz2 |
cmArgumentParser: Propagate constructors through binding wrapper types
-rw-r--r-- | Source/cmArgumentParserTypes.h | 40 | ||||
-rw-r--r-- | Tests/CMakeLib/testArgumentParser.cxx | 14 |
2 files changed, 54 insertions, 0 deletions
diff --git a/Source/cmArgumentParserTypes.h b/Source/cmArgumentParserTypes.h index 9afa5c7..fe8e4ca 100644 --- a/Source/cmArgumentParserTypes.h +++ b/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 diff --git a/Tests/CMakeLib/testArgumentParser.cxx b/Tests/CMakeLib/testArgumentParser.cxx index 5460356..dad5b85 100644 --- a/Tests/CMakeLib/testArgumentParser.cxx +++ b/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()); |