From 32f990068e01c7f652fadc0f35d29ecbfa3d0c1e Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Tue, 15 Nov 2016 17:44:58 +0100 Subject: [PATCH] more --- include/continuable/continuable.hpp | 50 ++++++++++++++++++++++------- incubator.cpp | 25 +++++++++++---- 2 files changed, 56 insertions(+), 19 deletions(-) diff --git a/include/continuable/continuable.hpp b/include/continuable/continuable.hpp index cec322b..5249b83 100644 --- a/include/continuable/continuable.hpp +++ b/include/continuable/continuable.hpp @@ -120,6 +120,9 @@ auto appendHandlerToContinuation(Continuation&& cont, Handler&& handler) { #include #include +template +struct fail : std::enable_if_t::value, std::true_type> { }; + // Equivalent to C++17's std::void_t which is targets a bug in GCC, // that prevents correct SFINAE behavior. // See http://stackoverflow.com/questions/35753920 for details. @@ -144,7 +147,7 @@ class ContinuableBase; inline auto emptyContinuation() { return [](auto&& callback) { - std::forward(callback)(); + /*std::forward(*/callback/*)*/(); }; } @@ -152,6 +155,11 @@ inline auto emptyCallback() { return [](auto&&...) { }; } +struct FinalCallback { + template + void operator() (Args&&...) const { } +}; + template auto applyTuple(std::integer_sequence, T&& tuple, F&& function) { return std::forward(function)(std::get(std::forward(tuple))...); @@ -220,11 +228,12 @@ struct ArgumentsHint : std::true_type { using only_argument_type = OnlyArgument; }; +struct AbsentArgumentsTag { }; + template<> -struct ArgumentsHint : std::false_type { }; - -using AbsentArgumentsHint = ArgumentsHint; +struct ArgumentsHint : std::false_type { }; +using AbsentArgumentsHint = ArgumentsHint; using EmptyArgumentsHint = ArgumentsHint<>; template @@ -334,10 +343,10 @@ struct CallbackResultDecorator { }; /// No decoration is needed for continuables -template -struct CallbackResultDecorator>{ +template +struct CallbackResultDecorator>{ template - static auto decorate(Callback&& callback) -> std::decay_t { + static auto decorate(Callback&& callback) { return std::forward(callback); } }; @@ -375,6 +384,14 @@ struct CallbackResultDecorator> { } }; +template +void finalInvoke(std::true_type, Result&&, Next&&) { } + +template +void finalInvoke(std::false_type, Result&& result, Next&& next) { + std::forward(result)(std::forward(next)); +} + /// Create the proxy callback that is responsible for invoking /// the real callback and passing the next continuation into /// the result of the following callback. @@ -387,8 +404,10 @@ auto createProxyCallback(Callback&& callback, // if not, we need to decorate it. using Result = decltype(callback(std::forward(args)...)); using Decorator = CallbackResultDecorator; - Decorator::decorate(std::move(callback)) - (std::forward(args)...)(std::move(next)); + auto callable = Decorator::decorate(std::move(callback)); + auto result = std::move(callable)(std::forward(args)...); + finalInvoke(std::is_same>{}, + std::move(result), std::move(next)); }; } @@ -408,7 +427,14 @@ void invokeUndecorated(Data data) { // Check whether the ownership is acquired and start the continuation call if (data.ownership.hasOwnership()) { // Pass an empty callback to the continuation to invoke it - std::move(data.continuation)(emptyCallback()); + auto cont = std::move(data.continuation); // (emptyCallback()); + + // auto fn = &decltype(cont)::operator(); + // cont([](auto&&...) { }); + + cont(FinalCallback{}); + + int i = 0; } } @@ -495,12 +521,12 @@ private: template auto undecorateCombined(Identity, - std::tuple combined) { + std::tuple /*combined*/) { } template -auto undecorateCombined(std::tuple combined) { +auto undecorateCombined(std::tuple /*combined*/) { // using TargetArgs = typename do_undecorate::argument_type; // return undecorateCombined(TargetArgs{}, std::move(combined)); } diff --git a/incubator.cpp b/incubator.cpp index f3d1709..b283d58 100644 --- a/incubator.cpp +++ b/incubator.cpp @@ -45,27 +45,38 @@ struct Debugable { template void operator() (C&& c) { + // fail cc; std::forward(c)(true); } }; static auto moveTo() { - /*return make_continuable([](auto&& callback) { + return make_continuable([](auto&& callback) { callback(true); - });*/ + }); - return make_continuable(Debugable{}); + // return make_continuable(Debugable{}); } int main(int, char**) { Debugable deb; - // moveTo().then([](bool) {}); + auto empty = [](auto&&...) {}; + + deb(empty); + + moveTo() + .then([](bool) { + return make_continuable(Debugable{}); + }) + .then([](bool) { + + }); // continuable c; - auto dispatcher = SelfDispatcher{}; + // auto dispatcher = SelfDispatcher{}; /*(makeTestContinuation() && makeTestContinuation()) .undecorateFor([]() @@ -85,7 +96,7 @@ int main(int, char**) { // auto combined = makeTestContinuation() && makeTestContinuation(); int res = 0; - makeTestContinuation() + /*makeTestContinuation() .then([](std::string) { return std::make_tuple(47, 46, 45); }) @@ -102,7 +113,7 @@ int main(int, char**) { .then(makeTestContinuation()) .then([] (std::string arg) { arg.clear(); - }); + });*/ return res; }