diff --git a/fluent/Continuable.h b/fluent/Continuable.h index 64f79e3..c22d2ed 100644 --- a/fluent/Continuable.h +++ b/fluent/Continuable.h @@ -48,15 +48,16 @@ namespace detail { typedef _ContinuableImpl> type; - template - static type InvokeAndReturn(std::function const& functional, std::forward... args) - { - functional(std::forward(args)...); - return type(); /*[](Callback<>&& callback) - { - callback(); - });*/ - } + + //template + //static type InvokeAndReturn(std::function const& functional, std::forward... args) + //{ + // functional(std::forward(args)...); + // return type(); /*[](Callback<>&& callback) + // { + // callback(); + // });*/ + //} }; template @@ -64,11 +65,11 @@ namespace detail { typedef _ContinuableImpl<_State, _CTy> type; - template - static type InvokeAndReturn(std::function const& functional, std::forward... args) - { - return functional(std::forward(args)...); - } + //template + //static type InvokeAndReturn(std::function const& functional, std::forward... args) + //{ + // return functional(std::forward(args)...); + //} }; template @@ -143,7 +144,7 @@ namespace detail : _callback_insert(std::forward<_FTy>(callback_insert)), _released(false), _entry_point() { } template - _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 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 - }); + }); + */ } /* diff --git a/test.cpp b/test.cpp index 7a547a2..8d716e4 100644 --- a/test.cpp +++ b/test.cpp @@ -30,6 +30,14 @@ Continuable CastSpell(int id) }); } +Continuable Validate() +{ + return make_continuable([=](Callback&& callback) + { + callback(true); + }); +} + template void test_unwrap(std::string const& msg) { @@ -85,16 +93,23 @@ int main(int /*argc*/, char** /*argv*/) typedef Continuable myty1; typedef Continuable myty2; + // Convertible test + // Continuable> 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 cba1 = make_continuable([=](Callback&&) @@ -144,22 +159,22 @@ int main(int /*argc*/, char** /*argv*/) }; }; - // Entry point - std::function&&>)> entry = [continuable_1 /*= move*/, callback_by_user_1 /*given by the user (::then(...))*/] - (std::function&&)>) - { - // 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&&)> fn2 = callback_by_user_1(/*forward args*/ result); - return std::move(fn2); - }); - }; + //// Entry point + //std::function&&>)> entry = [continuable_1 /*= move*/, callback_by_user_1 /*given by the user (::then(...))*/] + // (std::function&&)>) + //{ + // // 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&&)> 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;