more tests

This commit is contained in:
Denis Blank 2015-06-10 18:01:34 +02:00 committed by Naios
parent c0d62c822f
commit 38338dfea5
5 changed files with 54 additions and 34 deletions

View File

@ -40,7 +40,7 @@ namespace detail
struct do_unwrap_callback;
template<typename... Args>
struct do_unwrap_callback<std::tuple<Args...>>
struct do_unwrap_callback<::fu::identity<Args...>>
{
typedef Callback<Args...> CallbackType;

View File

@ -21,36 +21,32 @@
#include "Callback.h"
template <typename _CTy>
struct Continuable;
template <typename _MTy>
class ContinuableBase
{
};
template <typename _CTy, typename _WTy = void>
class Continuable;
template <typename... _ATy, typename _WTy>
class Continuable<Callback<_ATy...>, typename _WTy>
template <typename... _ATy>
struct Continuable<Callback<_ATy...>>
{
public:
template <typename _CTy>
Continuable<Callback<_ATy...>>& then(_CTy&& callback)
{
return *this;
}
};
namespace detail
{
template <typename _FTy, typename _RTy, typename... _ATy>
template <typename _FTy, typename _RTy, typename _ATy>
struct ContinuableFactory;
template <typename _FTy, typename _RTy, typename... _ATy>
struct ContinuableFactory<_FTy, _RTy, std::tuple<_ATy...>>
template <typename _FTy, typename _RTy, typename _ATy>
struct ContinuableFactory<_FTy, _RTy, ::fu::identity<_ATy>>
{
static auto CreateFrom(_FTy&& functional)
-> int
-> _FTy// Continuable<_ATy>
{
return 1;
return _FTy; // Continuable<_ATy>();
}
};
@ -62,9 +58,9 @@ namespace detail
template <typename _FTy>
inline auto make_continuable(_FTy&& functional)
-> decltype(typename detail::continuable_factory_t<_FTy>::CreateFrom(std::declval<_FTy>()))
-> int// decltype(typename detail::continuable_factory_t<_FTy>::CreateFrom(std::declval<_FTy>()))
{
return detail::continuable_factory_t<_FTy>::CreateFrom(std::forward<_FTy>(functional));
return 1; // detail::continuable_factory_t<_FTy>::CreateFrom(std::forward<_FTy>(functional));
}
#endif /// _CONTINUABLE_H_

View File

@ -39,7 +39,7 @@ class WeakCallbackContainer
struct ProxyFactory;
template<typename _CTy, typename... Args>
struct ProxyFactory<_CTy, std::tuple<Args...>>
struct ProxyFactory<_CTy, ::fu::identity<Args...>>
{
// Creates a weak proxy callback which prevents invoking to an invalid context.
// Removes itself from the owner with the given handler.

View File

@ -25,10 +25,14 @@
#define _FUNCTIONAL_UNWRAP_HPP_
#include <functional>
#include <tuple>
namespace fu
{
template<typename... Args>
struct identity
{
};
namespace detail
{
template<typename Function>
@ -40,8 +44,8 @@ namespace fu
/// The return type of the function.
typedef _RTy return_type;
/// The argument types of the function as pack in std::tuple.
typedef std::tuple<_ATy...> argument_type;
/// The argument types of the function as pack in fu::identity.
typedef identity<_ATy...> argument_type;
/// The function provided as std::function
typedef std::function<_RTy(_ATy...)> function_type;
@ -70,6 +74,11 @@ namespace fu
struct unwrap_function_impl<_RTy(_CTy::*)(_ATy...) const>
: unwrap_function_impl<_RTy(_ATy...)> { };
/// Pack in fu::identity
template<typename _RTy, typename... _ATy>
struct unwrap_function_impl<identity<_RTy, _ATy...>>
: unwrap_function_impl<_RTy(_ATy...)> { };
/// Unwrap through pointer of functor.
template<typename Function>
static auto select_best_unwrap_unary_arg(int)

View File

@ -42,19 +42,19 @@ void ProtoCastSpell(int id, Callback<SpellCastResult> const& callback)
callback(SPELL_FAILED_SUCCESS);
}
/*Continuable<SpellCastResult>*/ int CastSpell(int id)
Continuable<Callback<SpellCastResult>>
CastSpell(int id)
{
auto lam = [=](Callback<SpellCastResult> const& callback)
auto tt = 1;
/*make_continuable([=](Callback<SpellCastResult> const& callback)
{
std::cout << "Cast " << id << std::endl;
// on success call the callback with SPELL_FAILED_SUCCESS
callback(SPELL_FAILED_SUCCESS);
};
});*/
auto ct = make_continuable(std::move(lam));
return detail::ContinuableFactory<decltype(lam), void, std::tuple<Callback<SpellCastResult> const&>>::CreateFrom(std::move(lam));
return Continuable<Callback<SpellCastResult>>();
}
void ProtoMoveTo(int point, Callback<bool> const& callback)
@ -173,14 +173,29 @@ int main(int argc, char** argv)
wrapped2();
*/
typedef Continuable<Callback<bool>> cont;
typedef Continuable<Callback<bool>> cont123;
// typedef Continuable<Callback<bool>>::type myty1;
// typedef Continuable<Callback<bool>, float>::type myty2;
// Continuable<Callback<SpellCastResult>>
CastSpell(63362)
.then([](SpellCastResult result)
{
CastSpell(2);
return CastSpell(63362);
})
.then([](SpellCastResult result)
{
// Wraps a callback function into a continuable
return make_continuable([=](Callback<SpellCastResult> callback)
{
});
});
return 0;
}