diff --git a/include/Continuable.h b/include/Continuable.h index 4b53f72..c4473aa 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -19,6 +19,9 @@ #ifndef _CONTINUABLE_H_ #define _CONTINUABLE_H_ +// debug +#include + #include #include @@ -522,7 +525,9 @@ namespace detail template inline static void invoke(shared_result_t storage, Arguments&& args, _CTy&& current) { - std::cout << "invoking: " << Position << std::endl; + auto&& corrected = functional_traits<_ATy...>::correct(std::forward<_CTy>(current)); + + std::cout << "invoking: " << Position << " " << typeid(corrected).name() << std::endl; } /// Invoke and pass recursive to itself @@ -535,29 +540,50 @@ namespace detail } }; + template + struct sequenced_invoke; + + template + struct sequenced_invoke> + { + template + inline static void invoke(shared_result_t result, Arguments&& arguments, TupleFunctional&& functional) + { + distributor<_PTy...>::invoke( + result, + std::forward(arguments), + std::get(std::forward(functional))... + ); + } + }; + /// Creates a faked function which invokes all sub continuables template static return_t create(_CTy&&... functionals) { + // C++11 workaround for move semantics of non copyable types + auto shared_functionals = std::make_shared>( + std::make_tuple(std::forward<_CTy>(functionals)...) + ); + return [=](_ATy&&... args) mutable { + auto shared_args = std::make_shared>(std::make_tuple(std::forward<_ATy>(args)...)); + // Fake continuable which wraps all continuables together return make_continuable([=](Callback<_RTy...>&& callback) mutable { shared_result_t result(new ResultStorage(sizeof...(_CTy))); - distributor<_PTy...>::invoke( + sequenced_invoke< + fu::sequence_of_t< + sizeof...(_CTy) + > + >::invoke( result, - std::make_tuple(std::forward<_ATy>(args)...), - std::forward<_CTy>(functionals)...); - - // distributor_from_identity - - // invoke(result, std::forward<_CTy>(functionals)...); - - // functional_traits<_ATy...>::correct(std::forward<_CTy>(functionals)) - - // auto shared = std::make_shared(ResultStorage()); + std::move(*shared_args), + std::move(*shared_functionals) + ); int i = 0; ++i; diff --git a/test.cpp b/test.cpp index 525669a..6f2fff3 100644 --- a/test.cpp +++ b/test.cpp @@ -423,10 +423,8 @@ int main(int /*argc*/, char** /*argv*/) callback(true, false); }); }, - [] { - return CastSpellPromise(25); - }) - .then([](SpellCastResult, SpellCastResult, bool, bool, SpellCastResult) + TrivialPromise()) + .then([](SpellCastResult, SpellCastResult, bool, bool) { })