aboutsummaryrefslogtreecommitdiff
path: root/lib/function_traits.h
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-07-08 17:42:07 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-07-08 17:42:07 +0200
commitb5334cbfc18eddd599164fb255c2cabc6720d77c (patch)
tree63d460f5f2aa130e5d804bd74d33363260f2e414 /lib/function_traits.h
parent8580043a64941e1c1f132737e4b50280ac17812a (diff)
parent3f586005840e012a98e0f300a726b1cbda75e001 (diff)
downloadlibquotient-b5334cbfc18eddd599164fb255c2cabc6720d77c.tar.gz
libquotient-b5334cbfc18eddd599164fb255c2cabc6720d77c.zip
Merge remote-tracking branch 'origin/kitsune/c++20-galore' into dev
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