aboutsummaryrefslogtreecommitdiff
path: root/lib/function_traits.h
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-08-24 09:41:51 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-08-24 09:41:51 +0200
commit82f4efb0227e7e22e831733fae3952818b063ac2 (patch)
tree3b154a16f9d355996a59c611230d0e010edab57f /lib/function_traits.h
parent16d4f4e48304543a0ab59b235edba07f5f2c2204 (diff)
parent6308bff3336ca7680eee54d9bd125f780fa9f033 (diff)
downloadlibquotient-82f4efb0227e7e22e831733fae3952818b063ac2.tar.gz
libquotient-82f4efb0227e7e22e831733fae3952818b063ac2.zip
Merge branch 'dev' into device-verification
# Conflicts: # autotests/testfilecrypto.cpp # lib/connection.cpp # lib/connection.h # lib/database.cpp # lib/database.h # lib/e2ee/qolmoutboundsession.cpp # lib/e2ee/qolmoutboundsession.h # lib/eventitem.h # lib/events/encryptedevent.cpp # lib/events/encryptedevent.h # lib/events/encryptedfile.cpp # lib/events/encryptedfile.h # lib/events/keyverificationevent.cpp # lib/events/keyverificationevent.h # lib/events/roomkeyevent.h # lib/room.cpp # lib/room.h
Diffstat (limited to 'lib/function_traits.h')
-rw-r--r--lib/function_traits.h36
1 files changed, 18 insertions, 18 deletions
diff --git a/lib/function_traits.h b/lib/function_traits.h
index 83b8e425..143ed162 100644
--- a/lib/function_traits.h
+++ b/lib/function_traits.h
@@ -8,7 +8,7 @@
namespace Quotient {
namespace _impl {
- template <typename AlwaysVoid, typename>
+ template <typename>
struct fn_traits {};
}
@@ -21,73 +21,73 @@ namespace _impl {
*/
template <typename T>
struct function_traits
- : public _impl::fn_traits<void, std::remove_reference_t<T>> {};
+ : public _impl::fn_traits<std::remove_reference_t<T>> {};
// Specialisation for a function
template <typename ReturnT, typename... ArgTs>
struct function_traits<ReturnT(ArgTs...)> {
using return_type = ReturnT;
using arg_types = std::tuple<ArgTs...>;
- // See also the comment for wrap_in_function() in qt_connection_util.h
- using function_type = std::function<ReturnT(ArgTs...)>;
};
namespace _impl {
- template <typename AlwaysVoid, typename>
+ template <typename>
struct fn_object_traits;
// Specialisation for a lambda function
template <typename ReturnT, typename ClassT, typename... ArgTs>
- struct fn_object_traits<void, ReturnT (ClassT::*)(ArgTs...)>
+ struct fn_object_traits<ReturnT (ClassT::*)(ArgTs...)>
: function_traits<ReturnT(ArgTs...)> {};
// Specialisation for a const lambda function
template <typename ReturnT, typename ClassT, typename... ArgTs>
- struct fn_object_traits<void, ReturnT (ClassT::*)(ArgTs...) const>
+ struct fn_object_traits<ReturnT (ClassT::*)(ArgTs...) const>
: function_traits<ReturnT(ArgTs...)> {};
// Specialisation for function objects with (non-overloaded) operator()
// (this includes non-generic lambdas)
template <typename T>
- struct fn_traits<decltype(void(&T::operator())), T>
- : public fn_object_traits<void, decltype(&T::operator())> {};
+ requires requires { &T::operator(); }
+ struct fn_traits<T>
+ : public fn_object_traits<decltype(&T::operator())> {};
// Specialisation for a member function in a non-functor class
template <typename ReturnT, typename ClassT, typename... ArgTs>
- struct fn_traits<void, ReturnT (ClassT::*)(ArgTs...)>
+ struct fn_traits<ReturnT (ClassT::*)(ArgTs...)>
: function_traits<ReturnT(ClassT, ArgTs...)> {};
// Specialisation for a const member function
template <typename ReturnT, typename ClassT, typename... ArgTs>
- struct fn_traits<void, ReturnT (ClassT::*)(ArgTs...) const>
+ struct fn_traits<ReturnT (ClassT::*)(ArgTs...) const>
: function_traits<ReturnT(const ClassT&, ArgTs...)> {};
// Specialisation for a constref member function
template <typename ReturnT, typename ClassT, typename... ArgTs>
- struct fn_traits<void, ReturnT (ClassT::*)(ArgTs...) const&>
+ struct fn_traits<ReturnT (ClassT::*)(ArgTs...) const&>
: function_traits<ReturnT(const ClassT&, ArgTs...)> {};
// Specialisation for a prvalue member function
template <typename ReturnT, typename ClassT, typename... ArgTs>
- struct fn_traits<void, ReturnT (ClassT::*)(ArgTs...) &&>
+ struct fn_traits<ReturnT (ClassT::*)(ArgTs...) &&>
: function_traits<ReturnT(ClassT&&, ArgTs...)> {};
// Specialisation for a pointer-to-member
template <typename ReturnT, typename ClassT>
- struct fn_traits<void, ReturnT ClassT::*>
+ struct fn_traits<ReturnT ClassT::*>
: function_traits<ReturnT&(ClassT)> {};
// Specialisation for a const pointer-to-member
template <typename ReturnT, typename ClassT>
- struct fn_traits<void, const ReturnT ClassT::*>
+ struct fn_traits<const ReturnT ClassT::*>
: function_traits<const ReturnT&(ClassT)> {};
} // namespace _impl
-template <typename FnT>
-using fn_return_t = typename function_traits<FnT>::return_type;
-
template <typename FnT, int ArgN = 0>
using fn_arg_t =
std::tuple_element_t<ArgN, typename function_traits<FnT>::arg_types>;
+template <typename FnT>
+constexpr auto fn_arg_count_v =
+ std::tuple_size_v<typename function_traits<FnT>::arg_types>;
+
} // namespace Quotient