diff --git a/fluent++/Continuable.h b/fluent++/Continuable.h index 99ab6b6..c18b5ca 100644 --- a/fluent++/Continuable.h +++ b/fluent++/Continuable.h @@ -27,14 +27,16 @@ struct Continuable; template struct Continuable> { + typedef std::function&&)> ForwardFunction; + // Function which expects a callback that is inserted from the Continuable // to chain everything together - std::function)> _callback_insert; + ForwardFunction _callback_insert; public: Continuable>() { } - Continuable>(std::function)>&& callback_insert) - : _callback_insert(std::forward)>>(callback_insert)) { } + Continuable>(ForwardFunction&& callback_insert) + : _callback_insert(std::forward(callback_insert)) { } template Continuable>& then(_CTy&& callback) @@ -49,7 +51,7 @@ namespace detail struct ContinuableFactory; template - struct ContinuableFactory<_FTy, _RTy, ::fu::identity>> + struct ContinuableFactory<_FTy, _RTy, ::fu::identity&&>> { static auto CreateFrom(_FTy&& functional) -> Continuable> diff --git a/test.cpp b/test.cpp index 1f9e806..eb6ea55 100644 --- a/test.cpp +++ b/test.cpp @@ -18,6 +18,7 @@ enum SpellCastResult SPELL_FAILED_ALREADY_BEING_TAMED = 5 }; +/* ProtoContinueable ProtoCastSpell(int id) { std::cout << "Cast " << id << std::endl; @@ -40,23 +41,8 @@ void ProtoCastSpell(int id, Callback const& callback) // on success call the callback with SPELL_FAILED_SUCCESS callback(SPELL_FAILED_SUCCESS); -} - -Continuable> -CastSpell(int id) -{ - auto tt = 1; - /*make_continuable([=](Callback const& callback) - { - std::cout << "Cast " << id << std::endl; - - // on success call the callback with SPELL_FAILED_SUCCESS - callback(SPELL_FAILED_SUCCESS); - });*/ - - return Continuable>(); -} + void ProtoMoveTo(int point, Callback const& callback) { std::cout << "Move to point " << point << std::endl; @@ -65,8 +51,23 @@ void ProtoMoveTo(int point, Callback const& callback) callback(true); } +} +*/ + +Continuable> CastSpell(int id) +{ + return make_continuable([=](Callback&& callback) + { + std::cout << "Cast " << id << std::endl; + + // on success call the callback with SPELL_FAILED_SUCCESS + callback(SPELL_FAILED_SUCCESS); + }); +} + int main(int argc, char** argv) { + /* make_waterfall>() // .then(std::bind(&CastSpell, 71382, std::placeholders::_1)) .then([](SpellCastResult result, Callback const& callback) @@ -166,11 +167,12 @@ int main(int argc, char** argv) std::cout << "huhu" << std::endl; }); - /* + auto wrapped = make_weak_wrapped_callback(weak_2); auto wrapped2 = make_weak_wrapped_callback(WeakCallback<>(weak_2)); wrapped(); wrapped2(); + */ typedef Continuable> cont123; @@ -192,7 +194,7 @@ int main(int argc, char** argv) }); // Wraps a callback function into a continuable - auto cba1 = make_continuable([=](Callback callback) + auto cba1 = make_continuable([=](Callback&& callback) {