From dc08fb9dfd474023084de9ce86f29f177ca52fdc Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Thu, 2 Dec 2021 15:24:44 +0100 Subject: Improve function_traits<>; split out from util.* Quotient::function_traits<> did not support member functions in a proper way (i.e. the way std::invoke_result<> treats them, with the function's owning class represented as the first parameter). Now that I gained the skill and understanding in function_traits<> somewhat wicked machinery, I could properly support member functions. Overloads and generic lambdas are not supported but maybe we'll get to those one day. --- lib/function_traits.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 lib/function_traits.cpp (limited to 'lib/function_traits.cpp') diff --git a/lib/function_traits.cpp b/lib/function_traits.cpp new file mode 100644 index 00000000..4ff427e4 --- /dev/null +++ b/lib/function_traits.cpp @@ -0,0 +1,53 @@ +// SPDX-FileCopyrightText: 2018 Kitsune Ral +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "function_traits.h" + +// Tests for function_traits<> + +using namespace Quotient; + +int f_(); +static_assert(std::is_same, int>::value, + "Test fn_return_t<>"); + +void f1_(int, float); +static_assert(std::is_same, float>::value, + "Test fn_arg_t<>"); + +struct Fo { + int operator()(); + static constexpr auto l = [] { return 0.0f; }; + bool memFn(); + void constMemFn() const&; + double field; + const double field2; +}; +static_assert(std::is_same_v, int>, + "Test return type of function object"); +static_assert(std::is_same_v, float>, + "Test return type of lambda"); +static_assert(std::is_same_v, Fo>, + "Test first argument type of member function"); +static_assert(std::is_same_v, bool>, + "Test return type of member function"); +static_assert(std::is_same_v, const Fo&>, + "Test first argument type of const member function"); +static_assert(std::is_void_v>, + "Test return type of const member function"); +static_assert(std::is_same_v, double&>, + "Test return type of a class member"); +static_assert(std::is_same_v, const double&>, + "Test return type of a const class member"); + +struct Fo1 { + void operator()(int); +}; +static_assert(std::is_same, int>(), + "Test fn_arg_t defaulting to first argument"); + +template +static void ft(const std::vector&); +static_assert( + std::is_same)>, const std::vector&>(), + "Test function templates"); -- cgit v1.2.3 From c3a0515ac2ead7b2d0653be3517836cd31be480e Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Thu, 2 Dec 2021 21:18:30 +0100 Subject: Cleanup on Sonar issues --- lib/converters.h | 4 ++-- lib/function_traits.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/function_traits.cpp') diff --git a/lib/converters.h b/lib/converters.h index 90349019..9c3d5749 100644 --- a/lib/converters.h +++ b/lib/converters.h @@ -27,8 +27,8 @@ struct JsonObjectConverter { //! \brief The switchboard for extra conversion algorithms behind from/toJson //! //! This template is mainly intended for partial conversion specialisations -//! since from/toJson are functions and cannot be partially specialised; -//! another case for JsonConverter is to insulate types that can be constructed +//! since from/toJson are functions and cannot be partially specialised. +//! Another case for JsonConverter is to insulate types that can be constructed //! from basic types - namely, QVariant and QUrl can be directly constructed //! from QString and having an overload or specialisation for those leads to //! ambiguity between these and QJsonValue. For trivial (converting diff --git a/lib/function_traits.cpp b/lib/function_traits.cpp index 4ff427e4..20bcf30e 100644 --- a/lib/function_traits.cpp +++ b/lib/function_traits.cpp @@ -8,11 +8,11 @@ using namespace Quotient; int f_(); -static_assert(std::is_same, int>::value, +static_assert(std::is_same_v, int>, "Test fn_return_t<>"); void f1_(int, float); -static_assert(std::is_same, float>::value, +static_assert(std::is_same_v, float>, "Test fn_arg_t<>"); struct Fo { @@ -43,7 +43,7 @@ static_assert(std::is_same_v, const double&>, struct Fo1 { void operator()(int); }; -static_assert(std::is_same, int>(), +static_assert(std::is_same_v, int>, "Test fn_arg_t defaulting to first argument"); template -- cgit v1.2.3 From b17b629df44dbc888f6b6bee79d0d13d662371cf Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Tue, 18 Jan 2022 08:55:10 +0100 Subject: Add [[maybe_unused]] to things the lib doesn't use --- lib/function_traits.cpp | 2 +- lib/quotient_common.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/function_traits.cpp') diff --git a/lib/function_traits.cpp b/lib/function_traits.cpp index 20bcf30e..6542101a 100644 --- a/lib/function_traits.cpp +++ b/lib/function_traits.cpp @@ -47,7 +47,7 @@ static_assert(std::is_same_v, int>, "Test fn_arg_t defaulting to first argument"); template -static void ft(const std::vector&); +[[maybe_unused]] static void ft(const std::vector&); static_assert( std::is_same)>, const std::vector&>(), "Test function templates"); diff --git a/lib/quotient_common.h b/lib/quotient_common.h index af3e2730..02a9f0cd 100644 --- a/lib/quotient_common.h +++ b/lib/quotient_common.h @@ -95,7 +95,7 @@ enum class JoinState : std::underlying_type_t { }; QUO_DECLARE_FLAGS_NS(JoinStates, JoinState) -constexpr auto JoinStateStrings = make_array( +[[maybe_unused]] constexpr auto JoinStateStrings = make_array( MembershipStrings[0], MembershipStrings[1], MembershipStrings[2], MembershipStrings[3] /* same as MembershipStrings, sans "ban" */ ); @@ -125,7 +125,7 @@ enum RoomType { }; Q_ENUM_NS(RoomType) -constexpr auto RoomTypeStrings = make_array("m.space"); +[[maybe_unused]] constexpr auto RoomTypeStrings = make_array("m.space"); } // namespace Quotient Q_DECLARE_OPERATORS_FOR_FLAGS(Quotient::MembershipMask) -- cgit v1.2.3