From dbc78d185c4bafe03b458f9eeb7ef3af35ce2eb2 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Tue, 21 Jun 2022 07:33:43 +0200 Subject: SingleKeyValue: allow seamless construction from the underlying type SingleKeyValue is a tiny wrapper and supposed to be discreet. Having to explicitly (even if only with braces) construct its objects stands in the way of readability on the consuming side of the code and sometimes prevents direct initialisation of event objects without constructors getting some kind of ContentParamTs parameter pack where a single content_type argument would suffice otherwise. --- lib/events/single_key_value.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/events/single_key_value.h') diff --git a/lib/events/single_key_value.h b/lib/events/single_key_value.h index 75ca8cd2..5edff3b1 100644 --- a/lib/events/single_key_value.h +++ b/lib/events/single_key_value.h @@ -7,6 +7,15 @@ namespace Quotient { namespace EventContent { template struct SingleKeyValue { + // NOLINTBEGIN(google-explicit-constructor): that check should learn + // about explicit(false) + QUO_IMPLICIT SingleKeyValue(const T& v = {}) + : value { v } + {} + QUO_IMPLICIT SingleKeyValue(T&& v) + : value { std::move(v) } + {} + // NOLINTEND(google-explicit-constructor) T value; }; } // namespace EventContent -- cgit v1.2.3 From bd2736bc9f8b6023ecbc21d0d831856703b853db Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Tue, 21 Jun 2022 07:37:01 +0200 Subject: SingleKeyValue: use reference for template parameter I guess it was simply overlooked originally; in any case, currently used compilers deal with the reference just as fine as with the pointer. --- lib/events/single_key_value.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/events/single_key_value.h') diff --git a/lib/events/single_key_value.h b/lib/events/single_key_value.h index 5edff3b1..ca2bd331 100644 --- a/lib/events/single_key_value.h +++ b/lib/events/single_key_value.h @@ -5,7 +5,7 @@ namespace Quotient { namespace EventContent { - template + template struct SingleKeyValue { // NOLINTBEGIN(google-explicit-constructor): that check should learn // about explicit(false) @@ -20,7 +20,7 @@ namespace EventContent { }; } // namespace EventContent -template +template struct JsonConverter> { using content_type = EventContent::SingleKeyValue; static content_type load(const QJsonValue& jv) @@ -31,6 +31,6 @@ struct JsonConverter> { { return { { JsonKey, toJson(c.value) } }; } - static inline const auto JsonKey = toSnakeCase(*KeyStr); + static inline const auto JsonKey = toSnakeCase(KeyStr); }; } // namespace Quotient -- cgit v1.2.3