diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-10-02 09:36:02 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-10-02 09:36:02 +0900 |
commit | 1a1093b849df33baa5cee246d71e6ba63730c52f (patch) | |
tree | fbcdc6824f93746b19d08976030d0dfd3de33744 /lib/util.h | |
parent | bcd2179c78b26bd3150636ea255878f1caafc063 (diff) | |
download | libquotient-1a1093b849df33baa5cee246d71e6ba63730c52f.tar.gz libquotient-1a1093b849df33baa5cee246d71e6ba63730c52f.zip |
wrap_in_function()
Because Apple stdlib doesn't have std::function deduction guides.
Diffstat (limited to 'lib/util.h')
-rw-r--r-- | lib/util.h | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -149,19 +149,21 @@ namespace _impl { * https://stackoverflow.com/questions/7943525/is-it-possible-to-figure-out-the-parameter-type-and-return-type-of-a-lambda#7943765 */ template <typename T> -struct function_traits : public _impl::fn_traits<void, T> {}; +struct function_traits + : public _impl::fn_traits<void, 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...>; + // Doesn't (and there's no plan to make it) work for "classic" + // member functions (i.e. outside of functors). + // See also the comment for wrap_in_function() below + using function_type = std::function<ReturnT(ArgTs...)>; }; namespace _impl { - template <typename AlwaysVoid, typename T> - struct fn_traits; - // Specialisation for function objects with (non-overloaded) operator() // (this includes non-generic lambdas) template <typename T> @@ -186,6 +188,14 @@ template <typename FnT, int ArgN = 0> using fn_arg_t = std::tuple_element_t<ArgN, typename function_traits<FnT>::arg_types>; +// TODO: get rid of it as soon as Apple Clang gets proper deduction guides +// for std::function<> +template <typename FnT> +inline auto wrap_in_function(FnT&& f) +{ + return typename function_traits<FnT>::function_type(std::forward<FnT>(f)); +} + inline auto operator"" _ls(const char* s, std::size_t size) { return QLatin1String(s, int(size)); |