more work

This commit is contained in:
Naios 2015-06-15 23:09:01 +02:00
parent 6f1db0f52e
commit 417b3c8dae
2 changed files with 73 additions and 53 deletions

View File

@ -48,15 +48,16 @@ namespace detail
{ {
typedef _ContinuableImpl<DefaultContinuableState, Callback<>> type; typedef _ContinuableImpl<DefaultContinuableState, Callback<>> type;
template<typename Fn, typename... Args>
static type InvokeAndReturn(std::function<Fn> const& functional, std::forward<Args>... args) //template<typename Fn, typename... Args>
{ //static type InvokeAndReturn(std::function<Fn> const& functional, std::forward<Args>... args)
functional(std::forward<Args>(args)...); //{
return type(); /*[](Callback<>&& callback) // functional(std::forward<Args>(args)...);
{ // return type(); /*[](Callback<>&& callback)
callback(); // {
});*/ // callback();
} // });*/
//}
}; };
template<typename _State, typename _CTy> template<typename _State, typename _CTy>
@ -64,11 +65,11 @@ namespace detail
{ {
typedef _ContinuableImpl<_State, _CTy> type; typedef _ContinuableImpl<_State, _CTy> type;
template<typename Fn, typename... Args> //template<typename Fn, typename... Args>
static type InvokeAndReturn(std::function<Fn> const& functional, std::forward<Args>... args) //static type InvokeAndReturn(std::function<Fn> const& functional, std::forward<Args>... args)
{ //{
return functional(std::forward<Args>(args)...); // return functional(std::forward<Args>(args)...);
} //}
}; };
template<typename _NextRTy, typename... _NextATy> template<typename _NextRTy, typename... _NextATy>
@ -143,7 +144,7 @@ namespace detail
: _callback_insert(std::forward<_FTy>(callback_insert)), _released(false), _entry_point() { } : _callback_insert(std::forward<_FTy>(callback_insert)), _released(false), _entry_point() { }
template<typename _RSTy, typename _RCTy, typename _FTy> template<typename _RSTy, typename _RCTy, typename _FTy>
_ContinuableImpl(_ContinuableImpl<_RSTy, _RCTy>&& right, _FTy&& callback_insert) _ContinuableImpl(_FTy&& callback_insert, _ContinuableImpl<_RSTy, _RCTy>&& right)
: _callback_insert(std::forward<_FTy>(callback_insert)), _released(right._released), _entry_point() : _callback_insert(std::forward<_FTy>(callback_insert)), _released(right._released), _entry_point()
{ {
right._released = true; right._released = true;
@ -172,30 +173,34 @@ namespace detail
return *this; return *this;
} }
template<typename _CTy> template<typename _CTy>
auto then(_CTy&& functional) auto then(_CTy&& functional)
-> typename unary_chainer_t<_CTy>::result_t -> typename unary_chainer_t<_CTy>::result_t
{ {
// Next callback insert // Transfer the insert function to the local scope.
// Debugging // Also use it as an r-value reference to try to get move semantics with c++11.
// next(unary_chainer_t<_CTy>::callback_t()); ForwardFunction&& callback = std::move(_callback_insert);
return typename unary_chainer_t<_CTy>::result_t(
[functional, callback](typename unary_chainer_t<_CTy>::callback_t&& next)
{
callback([functional, next](_ATy... args)
{
typename unary_chainer_t<_CTy>::result_t continuable;
//= next(std::forward<_ATy>(args)...);
// continuable();
});
}, std::move(*this));
/*
return typename unary_chainer_t<_CTy>::result_t return typename unary_chainer_t<_CTy>::result_t
(std::move(*this), [=](typename unary_chainer_t<_CTy>::callback_t&& next_insert_callback) (std::move(*this), [=](typename unary_chainer_t<_CTy>::callback_t&& next_insert_callback)
{ {
_callback_insert([=](_ATy... args)
{
typename unary_chainer_t<_CTy>::result_t next =
functional(std::forward<_ATy>(args)...);
// next_insert_callback(result.);
// next._insert_callback(next_insert_callback);
// FIXME Call next callback
});
}); });
*/
} }
/* /*

View File

@ -30,6 +30,14 @@ Continuable<SpellCastResult> CastSpell(int id)
}); });
} }
Continuable<bool> Validate()
{
return make_continuable([=](Callback<bool>&& callback)
{
callback(true);
});
}
template <typename... T> template <typename... T>
void test_unwrap(std::string const& msg) void test_unwrap(std::string const& msg)
{ {
@ -85,16 +93,23 @@ int main(int /*argc*/, char** /*argv*/)
typedef Continuable<bool> myty1; typedef Continuable<bool> myty1;
typedef Continuable<bool, float> myty2; typedef Continuable<bool, float> myty2;
// Continuable<Callback<SpellCastResult>> spell // Convertible test
CastSpell(63362)
.then([](SpellCastResult)
{
return CastSpell(63362);
})
.then([](SpellCastResult)
{
}); // Continuable<Callback<SpellCastResult>> spell
{
auto stack = CastSpell(63362)
.then([](SpellCastResult)
{
return CastSpell(35254);
})
.then([](SpellCastResult)
{
return Validate();
});
int iii = 0;
iii = 1;
}
// Wraps a callback function into a continuable // Wraps a callback function into a continuable
Continuable<SpellCastResult> cba1 = make_continuable([=](Callback<SpellCastResult>&&) Continuable<SpellCastResult> cba1 = make_continuable([=](Callback<SpellCastResult>&&)
@ -144,22 +159,22 @@ int main(int /*argc*/, char** /*argv*/)
}; };
}; };
// Entry point //// Entry point
std::function<void(Callback<bool>&&>)> entry = [continuable_1 /*= move*/, callback_by_user_1 /*given by the user (::then(...))*/] //std::function<void(Callback<bool>&&>)> entry = [continuable_1 /*= move*/, callback_by_user_1 /*given by the user (::then(...))*/]
(std::function<void(Callback<bool>&&)>) // (std::function<void(Callback<bool>&&)>)
{ //{
// Call with auto created wrapper by the continuable // // Call with auto created wrapper by the continuable
continuable_1([&](SpellCastResult result /*forward args*/) // continuable_1([&](SpellCastResult result /*forward args*/)
{ // {
// Wrapper functional to process unary or multiple promised callbacks // // Wrapper functional to process unary or multiple promised callbacks
// Returned from the user // // Returned from the user
std::function<void(Callback<bool>&&)> fn2 = callback_by_user_1(/*forward args*/ result); // std::function<void(Callback<bool>&&)> fn2 = callback_by_user_1(/*forward args*/ result);
return std::move(fn2); // return std::move(fn2);
}); // });
}; //};
// Here we go //// Here we go
entry(); //entry();
std::cout << "ok" << std::endl; std::cout << "ok" << std::endl;
return 0; return 0;