aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-12-08 20:11:35 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-12-08 20:11:35 +0900
commit95d4df58b39962f771885a6615efe1a682aab356 (patch)
tree7184234e97f1ad56ce6c5c830a775bbbb9d89621
parent3489b77bba1b9429925dfe9539c2a9e8137fc622 (diff)
downloadlibquotient-95d4df58b39962f771885a6615efe1a682aab356.tar.gz
libquotient-95d4df58b39962f771885a6615efe1a682aab356.zip
function_traits: more tests, fix function objects/lambdas not working with some compilers
A member function reference is not the same as a member function pointer.
-rw-r--r--lib/util.cpp14
-rw-r--r--lib/util.h8
2 files changed, 14 insertions, 8 deletions
diff --git a/lib/util.cpp b/lib/util.cpp
index 4c176fc7..5e7644a1 100644
--- a/lib/util.cpp
+++ b/lib/util.cpp
@@ -100,10 +100,16 @@ struct S { int mf(); };
static_assert(is_callable_v<decltype(&S::mf)>, "Test member function");
static_assert(returns<int, decltype(&S::mf)>(), "Test returns<> with member function");
-struct Fo { void operator()(int); };
-static_assert(function_traits<Fo>::arg_number == 1, "Test function object 1");
-static_assert(is_callable_v<Fo>, "Test is_callable<>");
-static_assert(std::is_same<fn_arg_t<Fo>, int>(),
+struct Fo { int operator()(); };
+static_assert(is_callable_v<Fo>, "Test is_callable<> with function object");
+static_assert(function_traits<Fo>::arg_number == 0, "Test function object");
+static_assert(std::is_same<fn_return_t<Fo>, int>::value,
+ "Test return type of function object");
+
+struct Fo1 { void operator()(int); };
+static_assert(function_traits<Fo1>::arg_number == 1, "Test function object 1");
+static_assert(is_callable_v<Fo1>, "Test is_callable<> with function object 1");
+static_assert(std::is_same<fn_arg_t<Fo1>, int>(),
"Test fn_arg_t defaulting to first argument");
static auto l = [] { return 1; };
diff --git a/lib/util.h b/lib/util.h
index 722a7e3d..0066c03d 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -149,8 +149,8 @@ namespace QMatrixClient
{
static constexpr auto is_callable = true;
using return_type = ReturnT;
- using arg_types = std::tuple<ArgTs..., void>;
- static constexpr auto arg_number = std::tuple_size<arg_types>::value - 1;
+ using arg_types = std::tuple<ArgTs...>;
+ static constexpr auto arg_number = std::tuple_size<arg_types>::value;
};
namespace _impl {
@@ -161,8 +161,8 @@ namespace QMatrixClient
};
template <typename T>
- struct fn_traits<decltype(void(T::operator())), T>
- : public fn_traits<void, decltype(T::operator())>
+ struct fn_traits<decltype(void(&T::operator())), T>
+ : public fn_traits<void, decltype(&T::operator())>
{ }; // A generic function object that has (non-overloaded) operator()
// Specialisation for a member function