From f85b495ae222f071e064b29b4d462ae40e2937f4 Mon Sep 17 00:00:00 2001 From: Naios Date: Tue, 21 Jul 2015 18:46:46 +0200 Subject: [PATCH] First Step: Make use of lambda move capture. --- include/Continuable.h | 18 +++++++----------- test.cpp | 12 +----------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/include/Continuable.h b/include/Continuable.h index 3025a9c..616303b 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -172,21 +172,17 @@ public: typename detail::unary_chainer_t<_CTy, _ATy...>::arguments_t>::value, "Given function signature isn't correct, for now it must match strictly!"); - // 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 lambdas. - ForwardFunction&& callback = std::move(_callback_insert); - - auto&& corrected = detail::functional_traits<_ATy...>:: - correct(std::forward<_CTy>(functional)); - return typename detail::unary_chainer_t<_CTy, _ATy...>::continuable_t( - [corrected, callback](typename detail::unary_chainer_t<_CTy, _ATy...>::callback_t&& call_next) + [ + corrected = detail::functional_traits<_ATy...>::correct(std::forward<_CTy>(functional)), + callback = std::move(_callback_insert) + ] + (typename detail::unary_chainer_t<_CTy, _ATy...>::callback_t&& call_next) mutable { - callback([corrected, call_next](_ATy&&... args) mutable + callback([corrected = std::move(corrected), call_next](_ATy&&... args) mutable { // Invoke the next callback - corrected(std::forward<_ATy>(args)...) - .invoke(std::move(call_next)); + corrected(std::forward<_ATy>(args)...).invoke(std::move(call_next)); }); }, std::move(*this)); diff --git a/test.cpp b/test.cpp index 3f3ec79..1eb422d 100644 --- a/test.cpp +++ b/test.cpp @@ -638,19 +638,9 @@ int main(int /*argc*/, char** /*argv*/) }) .then([] { - + return Log("ok, now its really finished!").then(CastSpellPromise(2)); }); - std::function callable = [] - { - std::cout << "ok" << std::endl; - }; - - auto conv_test_1 = std::bind(callable); - - conv_test_1(1, 1); - - /* continuable_returner> test26151_start(std::unique_ptr(new int(5)));