diff --git a/fluent++/Callback.h b/fluent++/Callback.h index c469d63..3d7525c 100644 --- a/fluent++/Callback.h +++ b/fluent++/Callback.h @@ -40,7 +40,7 @@ namespace detail struct do_unwrap_callback; template - struct do_unwrap_callback> + struct do_unwrap_callback<::fu::identity> { typedef Callback CallbackType; diff --git a/fluent++/Continuable.h b/fluent++/Continuable.h index 86fad4a..76e8bf9 100644 --- a/fluent++/Continuable.h +++ b/fluent++/Continuable.h @@ -21,36 +21,32 @@ #include "Callback.h" +template +struct Continuable; - -template -class ContinuableBase -{ - -}; - -template -class Continuable; - -template -class Continuable, typename _WTy> +template +struct Continuable> { public: - + template + Continuable>& then(_CTy&& callback) + { + return *this; + } }; namespace detail { - template + template struct ContinuableFactory; - template - struct ContinuableFactory<_FTy, _RTy, std::tuple<_ATy...>> + template + struct ContinuableFactory<_FTy, _RTy, ::fu::identity<_ATy>> { static auto CreateFrom(_FTy&& functional) - -> int + -> _FTy// Continuable<_ATy> { - return 1; + return _FTy; // Continuable<_ATy>(); } }; @@ -62,9 +58,9 @@ namespace detail template inline auto make_continuable(_FTy&& functional) - -> decltype(typename detail::continuable_factory_t<_FTy>::CreateFrom(std::declval<_FTy>())) + -> int// decltype(typename detail::continuable_factory_t<_FTy>::CreateFrom(std::declval<_FTy>())) { - return detail::continuable_factory_t<_FTy>::CreateFrom(std::forward<_FTy>(functional)); + return 1; // detail::continuable_factory_t<_FTy>::CreateFrom(std::forward<_FTy>(functional)); } #endif /// _CONTINUABLE_H_ diff --git a/fluent++/WeakCallbackContainer.h b/fluent++/WeakCallbackContainer.h index ee66731..1066dfb 100644 --- a/fluent++/WeakCallbackContainer.h +++ b/fluent++/WeakCallbackContainer.h @@ -39,7 +39,7 @@ class WeakCallbackContainer struct ProxyFactory; template - struct ProxyFactory<_CTy, std::tuple> + struct ProxyFactory<_CTy, ::fu::identity> { // Creates a weak proxy callback which prevents invoking to an invalid context. // Removes itself from the owner with the given handler. diff --git a/fluent++/functional_unwrap.hpp b/fluent++/functional_unwrap.hpp index 5af50c0..481f587 100644 --- a/fluent++/functional_unwrap.hpp +++ b/fluent++/functional_unwrap.hpp @@ -25,10 +25,14 @@ #define _FUNCTIONAL_UNWRAP_HPP_ #include -#include namespace fu { + template + struct identity + { + }; + namespace detail { template @@ -40,8 +44,8 @@ namespace fu /// The return type of the function. typedef _RTy return_type; - /// The argument types of the function as pack in std::tuple. - typedef std::tuple<_ATy...> argument_type; + /// The argument types of the function as pack in fu::identity. + typedef identity<_ATy...> argument_type; /// The function provided as std::function typedef std::function<_RTy(_ATy...)> function_type; @@ -70,6 +74,11 @@ namespace fu struct unwrap_function_impl<_RTy(_CTy::*)(_ATy...) const> : unwrap_function_impl<_RTy(_ATy...)> { }; + /// Pack in fu::identity + template + struct unwrap_function_impl> + : unwrap_function_impl<_RTy(_ATy...)> { }; + /// Unwrap through pointer of functor. template static auto select_best_unwrap_unary_arg(int) diff --git a/test.cpp b/test.cpp index 6617237..a47e91d 100644 --- a/test.cpp +++ b/test.cpp @@ -42,19 +42,19 @@ void ProtoCastSpell(int id, Callback const& callback) callback(SPELL_FAILED_SUCCESS); } -/*Continuable*/ int CastSpell(int id) +Continuable> +CastSpell(int id) { - auto lam = [=](Callback const& callback) + 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); - }; + });*/ - auto ct = make_continuable(std::move(lam)); - - return detail::ContinuableFactory const&>>::CreateFrom(std::move(lam)); + return Continuable>(); } void ProtoMoveTo(int point, Callback const& callback) @@ -173,14 +173,29 @@ int main(int argc, char** argv) wrapped2(); */ - - typedef Continuable> cont; + typedef Continuable> cont123; // typedef Continuable>::type myty1; // typedef Continuable, float>::type myty2; + // Continuable> + CastSpell(63362) + .then([](SpellCastResult result) + { - CastSpell(2); + + return CastSpell(63362); + }) + .then([](SpellCastResult result) + { + // Wraps a callback function into a continuable + return make_continuable([=](Callback callback) + { + + + + }); + }); return 0; }