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; struct do_unwrap_callback;
template<typename... Args> template<typename... Args>
struct do_unwrap_callback<std::tuple<Args...>> struct do_unwrap_callback<::fu::identity<Args...>>
{ {
typedef Callback<Args...> CallbackType; typedef Callback<Args...> CallbackType;

View File

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

View File

@ -39,7 +39,7 @@ class WeakCallbackContainer
struct ProxyFactory; struct ProxyFactory;
template<typename _CTy, typename... Args> 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. // Creates a weak proxy callback which prevents invoking to an invalid context.
// Removes itself from the owner with the given handler. // Removes itself from the owner with the given handler.

View File

@ -25,10 +25,14 @@
#define _FUNCTIONAL_UNWRAP_HPP_ #define _FUNCTIONAL_UNWRAP_HPP_
#include <functional> #include <functional>
#include <tuple>
namespace fu namespace fu
{ {
template<typename... Args>
struct identity
{
};
namespace detail namespace detail
{ {
template<typename Function> template<typename Function>
@ -40,8 +44,8 @@ namespace fu
/// The return type of the function. /// The return type of the function.
typedef _RTy return_type; typedef _RTy return_type;
/// The argument types of the function as pack in std::tuple. /// The argument types of the function as pack in fu::identity.
typedef std::tuple<_ATy...> argument_type; typedef identity<_ATy...> argument_type;
/// The function provided as std::function /// The function provided as std::function
typedef std::function<_RTy(_ATy...)> function_type; typedef std::function<_RTy(_ATy...)> function_type;
@ -70,6 +74,11 @@ namespace fu
struct unwrap_function_impl<_RTy(_CTy::*)(_ATy...) const> struct unwrap_function_impl<_RTy(_CTy::*)(_ATy...) const>
: unwrap_function_impl<_RTy(_ATy...)> { }; : 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. /// Unwrap through pointer of functor.
template<typename Function> template<typename Function>
static auto select_best_unwrap_unary_arg(int) 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); 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; std::cout << "Cast " << id << std::endl;
// 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);
}; });*/
auto ct = make_continuable(std::move(lam)); return Continuable<Callback<SpellCastResult>>();
return detail::ContinuableFactory<decltype(lam), void, std::tuple<Callback<SpellCastResult> const&>>::CreateFrom(std::move(lam));
} }
void ProtoMoveTo(int point, Callback<bool> const& callback) void ProtoMoveTo(int point, Callback<bool> const& callback)
@ -173,14 +173,29 @@ int main(int argc, char** argv)
wrapped2(); wrapped2();
*/ */
typedef Continuable<Callback<bool>> cont123;
typedef Continuable<Callback<bool>> cont;
// typedef Continuable<Callback<bool>>::type myty1; // typedef Continuable<Callback<bool>>::type myty1;
// typedef Continuable<Callback<bool>, float>::type myty2; // 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; return 0;
} }