some workarrounds for clang...

This commit is contained in:
Naios 2015-06-10 15:23:43 +02:00
parent 53d62da254
commit 71ef5ed2ef
3 changed files with 37 additions and 6 deletions

View File

@ -54,14 +54,19 @@ namespace detail
template<typename... Args>
struct WeakProxyFactory
{
static Callback<Args...> CreateProxy(WeakCallback<Args...> const& weak_callback)
static Callback<Args...> CreateProxyFromWeak(WeakCallback<Args...> const& weak_callback)
{
return [=](Args&&... args)
{
if (auto const callback = weak_callback.lock())
(*callback)(args...);
(*callback)(args...); // FIXME: use std::forward
};
}
static Callback<Args...> CreateProxyFromShared(SharedCallback<Args...> const& shared_callback)
{
return CreateProxyFromWeak(WeakCallback<Args...>(shared_callback));
}
};
} // detail
@ -87,14 +92,16 @@ template<typename... Args>
inline auto make_weak_wrapped_callback(WeakCallback<Args...> const& weak_callback)
-> Callback<Args...>
{
return detail::WeakProxyFactory<Args...>::CreateProxy(weak_callback);
// Some workarounds for clang...
return detail::WeakProxyFactory<Args...>::CreateProxyFromWeak(weak_callback);
}
template<typename... Args>
inline auto make_weak_wrapped_callback(SharedCallback<Args...> const& shared_callback)
-> Callback<Args...>
{
return detail::WeakProxyFactory<Args...>::CreateProxy(WeakCallback<Args...>(shared_callback));
// Some workarounds for clang...
return detail::WeakProxyFactory<Args...>::CreateProxyFromShared(shared_callback);
}
#endif /// _CALLBACK_H_

23
fluent++/Continuable.h Normal file
View File

@ -0,0 +1,23 @@
/*
* Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CONTINUABLE_H_
#define _CONTINUABLE_H_
#endif /// _CONTINUABLE_H_

View File

@ -54,8 +54,7 @@ class WeakCallbackContainer
if (auto const callback = weak_callback.lock())
{
// Invoke the original callback
// FIXME: std::forward<Args..>(args...) causes errors when void
(*callback)(args...);
(*callback)(args...); // FIXME: use std::forward
// Unregister the callback
owner->InvalidateCallback(handle);
@ -82,6 +81,7 @@ public:
return *this;
}
/// Weak wraps the given callable.
template<typename _CTy>
auto Wrap(_CTy&& callback)
-> callback_of_t<_CTy>
@ -99,6 +99,7 @@ public:
return std::move(proxy);
}
/// Calls ::Wrap on the given callable,
template<typename _CTy>
inline auto operator()(_CTy&& callback)
-> decltype(Wrap(std::declval<_CTy>()))