diff --git a/fluent/Continuable.h b/fluent/Continuable.h index 5ff26ab..d6b679d 100644 --- a/fluent/Continuable.h +++ b/fluent/Continuable.h @@ -50,7 +50,7 @@ namespace detail }; template - struct convert_void_to_continuable < _ContinuableImpl<_State, _CTy> > + struct convert_void_to_continuable<_ContinuableImpl<_State, _CTy>> { typedef _ContinuableImpl<_State, _CTy> type; }; @@ -60,22 +60,11 @@ namespace detail // MSVC 12 has issues to detect the parameter pack otherwise. template - 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 result_t::CallbackFunction callback_t; - - /* - template - static auto chain(_CTy&&) - -> typename convert_void_to_continuable<_NextRTy>::type - // _ContinuableImpl> - { - return typename convert_void_to_continuable<_NextRTy>::type(); - // _ContinuableImpl>(); - } - */ }; template @@ -137,11 +126,12 @@ namespace detail _ContinuableImpl(_FTy&& callback_insert) : _callback_insert(std::forward<_FTy>(callback_insert)), _released(false), _entry_point() { } - /* - template - _ContinuableImpl(_ContinuableImpl, _RCTy>&& right, _FTy&& callback_insert) - : _callback_insert(std::forward<_FTy>(callback_insert)), _released(false), _entry_point() { } - */ + template + _ContinuableImpl(_ContinuableImpl<_RSTy, _RCTy>&& right, _FTy&& callback_insert) + : _callback_insert(std::forward<_FTy>(callback_insert)), _released(right._released), _entry_point() + { + right._released = true; + } /// Destructor which calls the dispatch chain if needed. ~_ContinuableImpl() @@ -171,7 +161,11 @@ namespace detail -> typename unary_chainer_t<_CTy>::result_t { // 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) { @@ -181,14 +175,7 @@ namespace detail // next_insert_callback(result.); // 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)); + }); } /* diff --git a/test.cpp b/test.cpp index 970effe..07baf33 100644 --- a/test.cpp +++ b/test.cpp @@ -120,36 +120,51 @@ int main(int /*argc*/, char** /*argv*/) callback(SPELL_FAILED_AFFECTING_COMBAT); }; - // Implemented by user std::function&&)>(SpellCastResult)> cn1 = [](SpellCastResult) { // Given by continuable + // Fn2 return [](Callback&& callback) { callback(true); }; }; + // Implemented by user + std::function&&)>(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 - std::function wr1 = [&cn1](SpellCastResult result) + std::function wr1 = [&](SpellCastResult result) { // Wrapper functional to process unary or multiple promised callbacks // Returned from the user std::function&&)> fn2 = cn1(result); - fn2([](bool val) + // Auto wrapper + fn2([&](bool value) { - // Finished - std::cout << "Callback chain finished! -> " << val << std::endl; + cn2(value); }); }; + // Call this to start the chain Callback<> entry = [&] { fn1(std::move(wr1)); }; + // Here we go entry(); std::cout << "ok" << std::endl;