make clang very happy

This commit is contained in:
Naios 2015-06-11 02:45:34 +02:00
parent be064f7038
commit 45318e500a
2 changed files with 37 additions and 39 deletions

View File

@ -52,25 +52,32 @@ namespace detail
template<typename _CTy> template<typename _CTy>
using unwrap_callback_t = do_unwrap_callback<::fu::function_type_of_t<_CTy>>; using unwrap_callback_t = do_unwrap_callback<::fu::function_type_of_t<_CTy>>;
/*
template<typename... Args> template<typename... Args>
struct WeakProxyFactory struct WeakProxyFactory;
{
static Callback<Args...> CreateProxyFromWeak(WeakCallback<Args...> const& weak_callback)
{
return [=](Args&&... args)
{
if (auto const callback = weak_callback.lock())
(*callback)(args...); // FIXME: use std::forward
};
}
static Callback<Args...> CreateProxyFromShared(SharedCallback<Args...> const& shared_callback) template<typename... Args>
{ struct WeakProxyFactory<std::weak_ptr<std::function<void(Args...)>>>
return CreateProxyFromWeak(WeakCallback<Args...>(shared_callback)); {
} static Callback<Args...> CreateProxy(WeakCallback<Args...> const& weak)
{
return [=](Args&&... args)
{
if (auto const callback = weak.lock())
// FIXME: use std::forward
(*callback)(args...);
};
}
}; };
**/
template<typename... Args>
struct WeakProxyFactory<std::shared_ptr<std::function<void(Args...)>>>
{
static Callback<Args...> CreateProxy(SharedCallback<Args...> const& shared)
{
return WeakProxyFactory<std::weak_ptr<std::function<void(Args...)>>>::CreateProxy(shared);
}
};
} // detail } // detail
template<typename _CTy> template<typename _CTy>
@ -90,22 +97,13 @@ inline shared_callback_of_t<_CTy>
(std::forward<callback_of_t<_CTy>>(callback)); (std::forward<callback_of_t<_CTy>>(callback));
}; };
/* /// Creates a weak callback which wrapps the given shared or weak callback.
template<typename... Args> /// If the given managed callback expires the callback is not invoked anymore.
inline auto make_weak_wrapped_callback(WeakCallback<Args...> const& weak_callback) template<typename _CTy>
-> Callback<Args...> inline auto make_weak_wrapped_callback(_CTy const& callback)
{ -> decltype(detail::WeakProxyFactory<_CTy>::CreateProxy(callback))
// Some workarounds for clang... {
return detail::WeakProxyFactory<Args...>::CreateProxyFromWeak(weak_callback); return detail::WeakProxyFactory<_CTy>::CreateProxy(callback);
} }
template<typename... Args>
inline auto make_weak_wrapped_callback(SharedCallback<Args...> const& shared_callback)
-> Callback<Args...>
{
// Some workarounds for clang...
return detail::WeakProxyFactory<Args...>::CreateProxyFromShared(shared_callback);
}
*/
#endif /// _CALLBACK_H_ #endif /// _CALLBACK_H_

View File

@ -33,7 +33,7 @@ int main(int argc, char** argv)
auto lam = [=](Callback<SpellCastResult>&& callback) auto lam = [=](Callback<SpellCastResult>&& callback)
{ {
// on success call the callback with SPELL_FAILED_SUCCESS // on success call the callback with SPELL_FAILED_SUCCESS
callback(SPELL_FAILED_SUCCESS); // callback(SPELL_FAILED_SUCCESS);
}; };
// static_assert(std::is_void<decltype(lam)>::value, "blub"); // static_assert(std::is_void<decltype(lam)>::value, "blub");
@ -44,16 +44,16 @@ int main(int argc, char** argv)
fu::function_type_of_t<Callback<int>> fun2; fu::function_type_of_t<Callback<int>> fun2;
shared_callback_of_t<Callback<int>> fun3; shared_callback_of_t<std::function<void(int)>> sc1;
weak_callback_of_t<Callback<int>> fun4; weak_callback_of_t<Callback<int>> sc2;
// make_weak_wrapped_callback(sc1); make_weak_wrapped_callback(sc1);
// make_weak_wrapped_callback(sc2); make_weak_wrapped_callback(sc2);
typedef Continuable<bool> cont123; typedef Continuable<bool> cont123;
// typedef Continuable<Callback<bool>>::type myty1; typedef Continuable<Callback<bool>> myty1;
// typedef Continuable<Callback<bool>, float>::type myty2; typedef Continuable<Callback<bool>, float> myty2;
// Continuable<Callback<SpellCastResult>> spell // Continuable<Callback<SpellCastResult>> spell
CastSpell(63362) CastSpell(63362)