first working example!

This commit is contained in:
Denis Blank 2015-06-16 13:15:09 +02:00 committed by Naios
parent 988dcf048a
commit 2c479d4c43
2 changed files with 29 additions and 31 deletions

View File

@ -21,6 +21,7 @@
#include "Callback.h" #include "Callback.h"
// Debug includes
#include <iostream> #include <iostream>
#include <typeinfo> #include <typeinfo>
#include <string> #include <string>
@ -33,7 +34,7 @@ void debug(std::string const& m)
{ {
std::cout << m << std::endl; std::cout << m << std::endl;
} }
/// Debug end
namespace detail namespace detail
{ {
@ -59,7 +60,7 @@ namespace detail
// creates an empty callback. // creates an empty callback.
template<typename _FTy> template<typename _FTy>
struct create_empty_callback_factory; struct create_empty_callback;
template<typename... _Cain, typename _Proxy> template<typename... _Cain, typename _Proxy>
struct ContinuableState<std::tuple<_Cain...>, _Proxy> struct ContinuableState<std::tuple<_Cain...>, _Proxy>
@ -85,7 +86,7 @@ namespace detail
fu::argument_type_of_t<typename std::decay<_CTy>::type>>; fu::argument_type_of_t<typename std::decay<_CTy>::type>>;
template<typename... Args> template<typename... Args>
struct create_empty_callback_factory<std::function<void(std::function<void(Args...)>&&)>> struct create_empty_callback<std::function<void(std::function<void(Args...)>&&)>>
{ {
static auto create() static auto create()
-> Callback<Args...> -> Callback<Args...>
@ -114,11 +115,18 @@ namespace detail
bool _released; bool _released;
public: template <typename _CTy>
// Empty for debugging _ContinuableImpl& operator()(_CTy callback)
/*_ContinuableImpl() {
: _released(true), _callback_insert() { }*/ // Invalidate this
_released = true;
// Invoke this
_callback_insert(std::forward<_CTy>(callback));
return *this;
}
public:
/// Deleted copy construct /// Deleted copy construct
_ContinuableImpl(_ContinuableImpl const&) = delete; _ContinuableImpl(_ContinuableImpl const&) = delete;
@ -147,13 +155,15 @@ namespace detail
// Dispatch everything. // Dispatch everything.
if (!_released) if (!_released)
{ {
log_type(_callback_insert, "invoke chain"); // log_type(_callback_insert, "invoke chain");
// Set released to true to prevent multiple calls // Set released to true to prevent multiple calls
_released = true; _released = true;
debug("invoking (once)");
// Invoke everything with an empty callback // Invoke everything with an empty callback
_callback_insert(create_empty_callback_factory<ForwardFunction>::create()); _callback_insert(create_empty_callback<ForwardFunction>::create());
} }
} }
@ -166,6 +176,7 @@ namespace detail
{ {
_released = right._released; _released = right._released;
right._released = true; right._released = true;
_callback_insert = std::move(right._callback_insert); _callback_insert = std::move(right._callback_insert);
return *this; return *this;
} }
@ -176,35 +187,18 @@ namespace detail
{ {
// Transfer the insert function to the local scope. // 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. // Also use it as an r-value reference to try to get move semantics with c++11.
ForwardFunction callback = std::move(_callback_insert); ForwardFunction&& callback = std::move(_callback_insert);
return typename unary_chainer_t<_CTy>::result_t( return typename unary_chainer_t<_CTy>::result_t(
[functional, callback](typename unary_chainer_t<_CTy>::callback_t&& call_next) [functional, callback](typename unary_chainer_t<_CTy>::callback_t&& call_next)
{ {
log_type(callback, "calling"); callback([functional, call_next](_ATy... args) mutable
callback([functional, call_next](_ATy... args)
{ {
log_type(functional, "invoking"); typename unary_chainer_t<_CTy>::result_t continuable =
auto continuable =
unary_chainer_t<_CTy>::base::invoke(functional, std::forward<_ATy>(args)...); unary_chainer_t<_CTy>::base::invoke(functional, std::forward<_ATy>(args)...);
// log_type(continuable, "result"); // Invoke the next callback
continuable(std::move(call_next));
// auto cc = continuable;
auto src_tttt = std::move(call_next);
auto tar_tttt = std::move(continuable._callback_insert);
tar_tttt(std::move(src_tttt));
int i = 0;
// TODO
// continuable._callback_insert(std::move(call_next));
}); });
}, std::move(*this)); }, std::move(*this));

View File

@ -55,6 +55,10 @@ int main(int /*argc*/, char** /*argv*/)
return CastSpell(2); return CastSpell(2);
}) })
.then([](SpellCastResult) .then([](SpellCastResult)
{
return Validate();
})
.then([](bool)
{ {
return CastSpell(3); return CastSpell(3);
}) })