mirror of
https://github.com/Naios/continuable.git
synced 2025-12-08 01:36:46 +08:00
more tests
This commit is contained in:
parent
c0d62c822f
commit
38338dfea5
@ -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;
|
||||
|
||||
|
||||
@ -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_
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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)
|
||||
|
||||
33
test.cpp
33
test.cpp
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user