more work

This commit is contained in:
Denis Blank 2015-06-15 23:09:01 +02:00 committed by Naios
parent fb76b97d91
commit 8534dbb8ac
2 changed files with 73 additions and 53 deletions

View File

@ -48,15 +48,16 @@ namespace detail
{
typedef _ContinuableImpl<DefaultContinuableState, Callback<>> type;
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)
{
callback();
});*/
}
//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)
// {
// callback();
// });*/
//}
};
template<typename _State, typename _CTy>
@ -64,11 +65,11 @@ namespace detail
{
typedef _ContinuableImpl<_State, _CTy> type;
template<typename Fn, typename... Args>
static type InvokeAndReturn(std::function<Fn> const& functional, std::forward<Args>... args)
{
return functional(std::forward<Args>(args)...);
}
//template<typename Fn, typename... Args>
//static type InvokeAndReturn(std::function<Fn> const& functional, std::forward<Args>... args)
//{
// return functional(std::forward<Args>(args)...);
//}
};
template<typename _NextRTy, typename... _NextATy>
@ -143,7 +144,7 @@ namespace detail
: _callback_insert(std::forward<_FTy>(callback_insert)), _released(false), _entry_point() { }
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()
{
right._released = true;
@ -172,30 +173,34 @@ namespace detail
return *this;
}
template<typename _CTy>
auto then(_CTy&& functional)
-> typename unary_chainer_t<_CTy>::result_t
{
// Next callback insert
// Debugging
// next(unary_chainer_t<_CTy>::callback_t());
// Transfer the insert function to the local scope.
// Also use it as an r-value reference to try to get move semantics with c++11.
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
(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>
void test_unwrap(std::string const& msg)
{
@ -85,16 +93,23 @@ int main(int /*argc*/, char** /*argv*/)
typedef Continuable<bool> myty1;
typedef Continuable<bool, float> myty2;
// Convertible test
// Continuable<Callback<SpellCastResult>> spell
CastSpell(63362)
.then([](SpellCastResult)
{
return CastSpell(63362);
})
.then([](SpellCastResult)
{
{
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
Continuable<SpellCastResult> cba1 = make_continuable([=](Callback<SpellCastResult>&&)
@ -144,22 +159,22 @@ int main(int /*argc*/, char** /*argv*/)
};
};
// 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>&&)>)
{
// Call with auto created wrapper by the continuable
continuable_1([&](SpellCastResult result /*forward args*/)
{
// Wrapper functional to process unary or multiple promised callbacks
// Returned from the user
std::function<void(Callback<bool>&&)> fn2 = callback_by_user_1(/*forward args*/ result);
return std::move(fn2);
});
};
//// 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>&&)>)
//{
// // Call with auto created wrapper by the continuable
// continuable_1([&](SpellCastResult result /*forward args*/)
// {
// // Wrapper functional to process unary or multiple promised callbacks
// // Returned from the user
// std::function<void(Callback<bool>&&)> fn2 = callback_by_user_1(/*forward args*/ result);
// return std::move(fn2);
// });
//};
// Here we go
entry();
//// Here we go
//entry();
std::cout << "ok" << std::endl;
return 0;