commit 48297ad: [Minor] Simplify array_of using types deduction

Vsevolod Stakhov vsevolod at rspamd.com
Sat Jun 11 12:42:03 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-06-11 12:24:23 +0100
URL: https://github.com/rspamd/rspamd/commit/48297adf9639ed9711c55560a26a09bee3da9dd7

[Minor] Simplify array_of using types deduction

---
 src/client/rspamc.cxx                | 2 +-
 src/libserver/html/html_tag_defs.hxx | 2 +-
 src/libutil/cxx/util.hxx             | 5 +++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/client/rspamc.cxx b/src/client/rspamc.cxx
index 2a2332bca..b7341be4f 100644
--- a/src/client/rspamc.cxx
+++ b/src/client/rspamc.cxx
@@ -214,7 +214,7 @@ struct rspamc_command {
 	void (*command_output_func)(FILE *, ucl_object_t *obj);
 };
 
-static const constexpr auto rspamc_commands = rspamd::array_of<rspamc_command>(
+static const constexpr auto rspamc_commands = rspamd::array_of(
 		rspamc_command{
 				.cmd = RSPAMC_COMMAND_SYMBOLS,
 				.name = "symbols",
diff --git a/src/libserver/html/html_tag_defs.hxx b/src/libserver/html/html_tag_defs.hxx
index 7e6cc9bf6..812ec2021 100644
--- a/src/libserver/html/html_tag_defs.hxx
+++ b/src/libserver/html/html_tag_defs.hxx
@@ -33,7 +33,7 @@ struct html_tag_def {
 
 #define TAG_DEF(id, name, flags) html_tag_def{(name), (id), (flags)}
 
-static const auto html_tag_defs_array = rspamd::array_of<html_tag_def>(
+static const auto html_tag_defs_array = rspamd::array_of(
 		/* W3C defined elements */
 		TAG_DEF(Tag_A, "a", FL_HREF),
 		TAG_DEF(Tag_ABBR, "abbr", (CM_INLINE)),
diff --git a/src/libutil/cxx/util.hxx b/src/libutil/cxx/util.hxx
index e45f16008..5b2020bb6 100644
--- a/src/libutil/cxx/util.hxx
+++ b/src/libutil/cxx/util.hxx
@@ -72,9 +72,10 @@ struct smart_ptr_hash {
 /*
  * Creates std::array from a standard C style array with automatic size calculation
  */
-template <typename V, typename... T>
-constexpr auto array_of(T&&... t) -> std::array<V, sizeof...(T)>
+template <typename... Ts>
+constexpr auto array_of(Ts&&... t) -> std::array<typename std::decay_t<typename std::common_type_t<Ts...>>, sizeof...(Ts)>
 {
+	using T = typename std::decay_t<typename std::common_type_t<Ts...>>;
 	return {{ std::forward<T>(t)... }};
 }
 


More information about the Commits mailing list