more work

This commit is contained in:
Denis Blank 2015-06-15 01:50:27 +02:00 committed by Naios
parent 8435bc4096
commit 2ed5f4e3dc
2 changed files with 34 additions and 32 deletions

View File

@ -50,7 +50,7 @@ namespace detail
}; };
template<typename _State, typename _CTy> template<typename _State, typename _CTy>
struct convert_void_to_continuable < _ContinuableImpl<_State, _CTy> > struct convert_void_to_continuable<_ContinuableImpl<_State, _CTy>>
{ {
typedef _ContinuableImpl<_State, _CTy> type; typedef _ContinuableImpl<_State, _CTy> type;
}; };
@ -60,22 +60,11 @@ namespace detail
// MSVC 12 has issues to detect the parameter pack otherwise. // MSVC 12 has issues to detect the parameter pack otherwise.
template<typename _NextRTy, typename... _NextATy> template<typename _NextRTy, typename... _NextATy>
struct unary_chainer< _NextRTy, fu::identity<_NextATy...>> struct unary_chainer<_NextRTy, fu::identity<_NextATy...>>
{ {
typedef typename convert_void_to_continuable<_NextRTy>::type result_t; typedef typename convert_void_to_continuable<_NextRTy>::type result_t;
typedef typename result_t::CallbackFunction callback_t; typedef typename result_t::CallbackFunction callback_t;
/*
template<typename _CTy>
static auto chain(_CTy&&)
-> typename convert_void_to_continuable<_NextRTy>::type
// _ContinuableImpl<DefaultContinuableState, Callback<_NextATy...>>
{
return typename convert_void_to_continuable<_NextRTy>::type();
// _ContinuableImpl<DefaultContinuableState, Callback<_NextATy...>>();
}
*/
}; };
template <typename _CTy> template <typename _CTy>
@ -137,11 +126,12 @@ namespace detail
_ContinuableImpl(_FTy&& callback_insert) _ContinuableImpl(_FTy&& callback_insert)
: _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 _RCTy, typename _FTy> _ContinuableImpl(_ContinuableImpl<_RSTy, _RCTy>&& right, _FTy&& callback_insert)
_ContinuableImpl(_ContinuableImpl<ContinuableState<_STy...>, _RCTy>&& right, _FTy&& callback_insert) : _callback_insert(std::forward<_FTy>(callback_insert)), _released(right._released), _entry_point()
: _callback_insert(std::forward<_FTy>(callback_insert)), _released(false), _entry_point() { } {
*/ right._released = true;
}
/// Destructor which calls the dispatch chain if needed. /// Destructor which calls the dispatch chain if needed.
~_ContinuableImpl() ~_ContinuableImpl()
@ -171,7 +161,11 @@ namespace detail
-> typename unary_chainer_t<_CTy>::result_t -> typename unary_chainer_t<_CTy>::result_t
{ {
// Next callback insert // Next callback insert
auto next = [=](typename unary_chainer_t<_CTy>::callback_t&& next_insert_callback) // Debugging
// next(unary_chainer_t<_CTy>::callback_t());
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) _callback_insert([=](_ATy... args)
{ {
@ -181,14 +175,7 @@ namespace detail
// next_insert_callback(result.); // next_insert_callback(result.);
// next._insert_callback(next_insert_callback); // next._insert_callback(next_insert_callback);
}); });
}; });
// Debugging
// next(unary_chainer_t<_CTy>::callback_t());
// decltype(unary_chainer_t<_CTy>::chain(std::declval<_CTy>()))
return typename unary_chainer_t<_CTy>::result_t();
// unary_chainer_t<_CTy>::chain(std::forward<_CTy>(functional));
} }
/* /*

View File

@ -120,36 +120,51 @@ int main(int /*argc*/, char** /*argv*/)
callback(SPELL_FAILED_AFFECTING_COMBAT); callback(SPELL_FAILED_AFFECTING_COMBAT);
}; };
// Implemented by user // Implemented by user
std::function<std::function<void(Callback<bool>&&)>(SpellCastResult)> cn1 = [](SpellCastResult) std::function<std::function<void(Callback<bool>&&)>(SpellCastResult)> cn1 = [](SpellCastResult)
{ {
// Given by continuable // Given by continuable
// Fn2
return [](Callback<bool>&& callback) return [](Callback<bool>&& callback)
{ {
callback(true); callback(true);
}; };
}; };
// Implemented by user
std::function<std::function<void(Callback<>&&)>(bool)> cn2 = [](bool val)
{
// Finished
std::cout << "Callback chain finished! -> " << val << std::endl;
// Given by continuable (auto end)
return [](Callback<>&&)
{
// Empty callback
};
};
// Auto created wrapper by the continuable // Auto created wrapper by the continuable
std::function<void(SpellCastResult)> wr1 = [&cn1](SpellCastResult result) std::function<void(SpellCastResult)> wr1 = [&](SpellCastResult result)
{ {
// 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 = cn1(result); std::function<void(Callback<bool>&&)> fn2 = cn1(result);
fn2([](bool val) // Auto wrapper
fn2([&](bool value)
{ {
// Finished cn2(value);
std::cout << "Callback chain finished! -> " << val << std::endl;
}); });
}; };
// Call this to start the chain
Callback<> entry = [&] Callback<> entry = [&]
{ {
fn1(std::move(wr1)); fn1(std::move(wr1));
}; };
// Here we go
entry(); entry();
std::cout << "ok" << std::endl; std::cout << "ok" << std::endl;