From 77fcb00a2b76518c0db861a96a8f4857a50b140e Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 26 Jul 2022 14:03:32 -0400 Subject: cmArgumentParser: Propagate constructors through binding wrapper types --- Source/cmArgumentParserTypes.h | 40 +++++++++++++++++++++++++++++++++++ Tests/CMakeLib/testArgumentParser.cxx | 14 ++++++++++++ 2 files changed, 54 insertions(+) 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 +# include + +namespace ArgumentParser { + +template +struct Maybe; +template <> +struct Maybe : public std::string +{ + using std::string::basic_string; +}; + +template +struct MaybeEmpty; +template +struct MaybeEmpty> : public std::vector +{ + using std::vector::vector; +}; + +template +struct NonEmpty; +template +struct NonEmpty> : public std::vector +{ + using std::vector::vector; +}; + +} // namespace ArgumentParser + +#else + namespace ArgumentParser { template struct Maybe : public T { + using T::T; }; template struct MaybeEmpty : public T { + using T::T; }; template 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>> Multi3; cm::optional>> Multi4; + ArgumentParser::Maybe UnboundMaybe{ 'u', 'n', 'b', 'o', + 'u', 'n', 'd' }; + ArgumentParser::MaybeEmpty> UnboundMaybeEmpty{ + 1, "unbound" + }; + ArgumentParser::NonEmpty> UnboundNonEmpty{ + 1, "unbound" + }; + std::vector ParsedKeywords; }; @@ -69,6 +78,7 @@ bool verifyResult(Result const& result, { static std::vector const foobar = { "foo", "bar" }; static std::vector const barfoo = { "bar", "foo" }; + static std::vector const unbound = { "unbound" }; static std::vector 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()); -- cgit v0.12