From 6dc592ad6b3a89b0f6fe20861635f5932d2cee61 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Thu, 11 Jun 2015 02:45:34 +0200 Subject: [PATCH] make clang very happy --- fluent/Callback.h | 62 +++++++++++++++++++++++------------------------ test.cpp | 14 +++++------ 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/fluent/Callback.h b/fluent/Callback.h index 756b32f..bd3eadf 100644 --- a/fluent/Callback.h +++ b/fluent/Callback.h @@ -52,25 +52,32 @@ namespace detail template using unwrap_callback_t = do_unwrap_callback<::fu::function_type_of_t<_CTy>>; - /* template - struct WeakProxyFactory - { - static Callback CreateProxyFromWeak(WeakCallback const& weak_callback) - { - return [=](Args&&... args) - { - if (auto const callback = weak_callback.lock()) - (*callback)(args...); // FIXME: use std::forward - }; - } + struct WeakProxyFactory; - static Callback CreateProxyFromShared(SharedCallback const& shared_callback) - { - return CreateProxyFromWeak(WeakCallback(shared_callback)); - } + template + struct WeakProxyFactory>> + { + static Callback CreateProxy(WeakCallback const& weak) + { + return [=](Args&&... args) + { + if (auto const callback = weak.lock()) + // FIXME: use std::forward + (*callback)(args...); + }; + } }; - **/ + + template + struct WeakProxyFactory>> + { + static Callback CreateProxy(SharedCallback const& shared) + { + return WeakProxyFactory>>::CreateProxy(shared); + } + }; + } // detail template @@ -90,22 +97,13 @@ inline shared_callback_of_t<_CTy> (std::forward>(callback)); }; -/* -template -inline auto make_weak_wrapped_callback(WeakCallback const& weak_callback) - -> Callback -{ - // Some workarounds for clang... - return detail::WeakProxyFactory::CreateProxyFromWeak(weak_callback); +/// Creates a weak callback which wrapps the given shared or weak callback. +/// If the given managed callback expires the callback is not invoked anymore. +template +inline auto make_weak_wrapped_callback(_CTy const& callback) + -> decltype(detail::WeakProxyFactory<_CTy>::CreateProxy(callback)) +{ + return detail::WeakProxyFactory<_CTy>::CreateProxy(callback); } -template -inline auto make_weak_wrapped_callback(SharedCallback const& shared_callback) - -> Callback -{ - // Some workarounds for clang... - return detail::WeakProxyFactory::CreateProxyFromShared(shared_callback); -} -*/ - #endif /// _CALLBACK_H_ diff --git a/test.cpp b/test.cpp index bdda4b2..e23df28 100644 --- a/test.cpp +++ b/test.cpp @@ -33,7 +33,7 @@ int main(int argc, char** argv) auto lam = [=](Callback&& callback) { // on success call the callback with SPELL_FAILED_SUCCESS - callback(SPELL_FAILED_SUCCESS); + // callback(SPELL_FAILED_SUCCESS); }; // static_assert(std::is_void::value, "blub"); @@ -44,16 +44,16 @@ int main(int argc, char** argv) fu::function_type_of_t> fun2; - shared_callback_of_t> fun3; - weak_callback_of_t> fun4; + shared_callback_of_t> sc1; + weak_callback_of_t> sc2; - // make_weak_wrapped_callback(sc1); - // make_weak_wrapped_callback(sc2); + make_weak_wrapped_callback(sc1); + make_weak_wrapped_callback(sc2); typedef Continuable cont123; - // typedef Continuable>::type myty1; - // typedef Continuable, float>::type myty2; + typedef Continuable> myty1; + typedef Continuable, float> myty2; // Continuable> spell CastSpell(63362)