diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-09-29 18:01:45 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-09-29 23:35:52 +0900 |
commit | 534a15d05e0b6e1b44b6387003e1475150e848e8 (patch) | |
tree | 696a2c04ce5a766f5485fdf97a0c764ee1daa90d /lib | |
parent | 72dd1eb7c1986c23a7630205e2f2a0280b7c2a2b (diff) | |
download | libquotient-534a15d05e0b6e1b44b6387003e1475150e848e8.tar.gz libquotient-534a15d05e0b6e1b44b6387003e1475150e848e8.zip |
function_traits: drop unused pieces
is_callable won't ever be needed because std::is_invokable is here; arg_number and returns() didn't find its users; and function_type has been just broken all along for member functions.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util.cpp | 38 | ||||
-rw-r--r-- | lib/util.h | 22 |
2 files changed, 6 insertions, 54 deletions
diff --git a/lib/util.cpp b/lib/util.cpp index cc18d9ab..041a8aba 100644 --- a/lib/util.cpp +++ b/lib/util.cpp @@ -141,63 +141,29 @@ int f(); static_assert(std::is_same<fn_return_t<decltype(f)>, int>::value, "Test fn_return_t<>"); -void f1(int); -static_assert(function_traits<decltype(f1)>::arg_number == 1, - "Test fn_arg_number"); - -void f2(int, QString); -static_assert(std::is_same<fn_arg_t<decltype(f2), 1>, QString>::value, +void f1(int, QString); +static_assert(std::is_same<fn_arg_t<decltype(f1), 1>, QString>::value, "Test fn_arg_t<>"); -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 { 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"); #if (!defined(_MSC_VER) || _MSC_VER >= 1910) static auto l = [] { return 1; }; -static_assert(is_callable_v<decltype(l)>, "Test is_callable_v<> with lambda"); static_assert(std::is_same<fn_return_t<decltype(l)>, int>::value, "Test fn_return_t<> with lambda"); #endif template <typename T> -struct fn_object { - static int smf(double) { return 0; } -}; -template <> -struct fn_object<QString> { - void operator()(QString); -}; -static_assert(is_callable_v<fn_object<QString>>, "Test function object"); -static_assert(returns<void, fn_object<QString>>(), - "Test returns<> with function object"); -static_assert(!is_callable_v<fn_object<int>>, "Test non-function object"); -// FIXME: These two don't work -// static_assert(is_callable_v<decltype(&fn_object<int>::smf)>, -// "Test static member function"); -// static_assert(returns<int, decltype(&fn_object<int>::smf)>(), -// "Test returns<> with static member function"); - -template <typename T> QString ft(T&&) { return {}; @@ -154,23 +154,19 @@ struct function_traits : public _impl::fn_traits<void, T> {}; // Specialisation for a function template <typename ReturnT, typename... ArgTs> struct function_traits<ReturnT(ArgTs...)> { - static constexpr auto is_callable = true; using return_type = ReturnT; using arg_types = std::tuple<ArgTs...>; - using function_type = std::function<ReturnT(ArgTs...)>; - static constexpr auto arg_number = std::tuple_size<arg_types>::value; }; namespace _impl { template <typename AlwaysVoid, typename T> - struct fn_traits { - static constexpr auto is_callable = false; - }; + struct fn_traits; + // 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_traits<void, decltype(&T::operator())> { - }; // A generic function object that has (non-overloaded) operator() + : public fn_traits<void, decltype(&T::operator())> {}; // Specialisation for a member function template <typename ReturnT, typename ClassT, typename... ArgTs> @@ -190,16 +186,6 @@ template <typename FnT, int ArgN = 0> using fn_arg_t = std::tuple_element_t<ArgN, typename function_traits<FnT>::arg_types>; -template <typename R, typename FnT> -constexpr bool returns() -{ - return std::is_same<fn_return_t<FnT>, R>::value; -} - -// Poor-man's is_invokable -template <typename T> -constexpr auto is_callable_v = function_traits<T>::is_callable; - inline auto operator"" _ls(const char* s, std::size_t size) { return QLatin1String(s, int(size)); |