From: TimePath Date: Sun, 31 Dec 2017 10:05:49 +0000 (+1100) Subject: Support lambda callbacks X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2d8381a1be1e00bfcc0bad5b53371875f8dd4956;p=xonotic%2Fnetradiant.git Support lambda callbacks --- diff --git a/libs/generic/callback.h b/libs/generic/callback.h index ef74e0cc..4110691e 100644 --- a/libs/generic/callback.h +++ b/libs/generic/callback.h @@ -148,7 +148,7 @@ public: }; template -using BindFirstOpaque = BindFirstOpaqueN; +using BindFirstOpaque = BindFirstOpaqueN>; template class CallbackN; diff --git a/libs/generic/functional.h b/libs/generic/functional.h index 7d76a8b0..8843e363 100644 --- a/libs/generic/functional.h +++ b/libs/generic/functional.h @@ -1,9 +1,56 @@ #if !defined( INCLUDED_FUNCTIONAL_H ) #define INCLUDED_FUNCTIONAL_H +#include #include namespace detail { + + template + struct rank : rank { + }; + + template<> + struct rank<0> { + }; + + struct get_func { + + template + struct wrapper { + using type = T; + }; + + template + using func_member = wrapper; + + template + static wrapper> test(rank<2>) { return {}; } + + template + struct func_lambda { + using type = typename func_lambda::type; + }; + + template + struct func_lambda { + using type = R(Ts...); + }; + + template + struct func_lambda { + using type = R(Ts...); + }; + + template + struct func_lambda { + using type = R(Ts...); + }; + + template> + static wrapper> test(rank<1>) { return {}; } + }; + template struct Fn; @@ -17,10 +64,13 @@ namespace detail { } template -using get_result_type = typename detail::Fn::result_type; +using get_func = typename decltype(detail::get_func::test(detail::rank<2>{}))::type::type; + +template +using get_result_type = typename detail::Fn>::result_type; template -using get_argument = typename detail::Fn::template get; +using get_argument = typename detail::Fn>::template get; template class MemberN; @@ -132,7 +182,7 @@ public: }; template -using FunctorInvoke = FunctorNInvoke; +using FunctorInvoke = FunctorNInvoke>; template using Member = typename MemberN::template instance; diff --git a/libs/signal/isignal.h b/libs/signal/isignal.h index c447d71b..9eaa9d0b 100644 --- a/libs/signal/isignal.h +++ b/libs/signal/isignal.h @@ -37,7 +37,7 @@ public: }; template -using SignalHandlerCaller = SignalHandlerCallerN; +using SignalHandlerCaller = SignalHandlerCallerN>; template using SignalHandlerCaller1 = SignalHandlerCaller;