From 103d8005f4cfa22284f87d459c0411d7750daabd Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Thu, 13 Oct 2016 00:12:05 +0200 Subject: [PATCH] Some minor things... --- CMakeLists.txt | 4 +- include/continuable/continuable.hpp | 73 +++++++---------------------- incubator.cpp | 55 ++++++++++++++++++++++ 3 files changed, 74 insertions(+), 58 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eff90ea..fd90f5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,9 @@ target_compile_features(continuable # Set up the test environment for testing if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) - add_executable(incubator "${CMAKE_CURRENT_LIST_DIR}/incubator.cpp") + add_executable(incubator + "${CMAKE_CURRENT_LIST_DIR}/include/continuable/continuable.hpp" + "${CMAKE_CURRENT_LIST_DIR}/incubator.cpp") target_link_libraries(incubator continuable) if (MSVC) diff --git a/include/continuable/continuable.hpp b/include/continuable/continuable.hpp index e2abf36..9c2eb46 100644 --- a/include/continuable/continuable.hpp +++ b/include/continuable/continuable.hpp @@ -173,12 +173,15 @@ auto tupleMerge(std::tuple&& left, std::move(left), std::move(right)); } +/// This class is responsible for holding an abstract copy- and +/// move-able ownership that is invalidated when the object +/// is moved to another instance. class Ownership { public: Ownership() { } explicit Ownership(bool isOwning_) : isOwning(isOwning_) { } Ownership(Ownership const&) = default; - explicit Ownership(Ownership&& right) noexcept + Ownership(Ownership&& right) noexcept : isOwning(std::exchange(right.isOwning, false)) { }; Ownership& operator = (Ownership const&) = default; Ownership& operator = (Ownership&& right) noexcept { @@ -196,6 +199,7 @@ public: void invalidate() { isOwning = false; } + private: bool isOwning{ true }; }; @@ -479,29 +483,29 @@ auto make_continuable(Continuation&& continuation, })); } -template -auto thenImpl(Data data, Callback&& callback) { - auto next = appendCallback(std::move(data.continuation), +template +auto thenImpl(Undecorated undecorated, Callback&& callback) { + auto next = appendCallback(std::move(undecorated.continuation), std::forward(callback)); using Decoration = DefaultDecoration + typename Undecorated::Config::template ChangeContinuationTo >>; return ContinuableBase(Decoration({ - std::move(data.ownership), + std::move(undecorated.ownership), std::move(next), - std::move(data.dispatcher) + std::move(undecorated.dispatcher) })); } -template -auto postImpl(Data data, NewDispatcher&& newDispatcher) { +template +auto postImpl(Undecorated undecorated, NewDispatcher&& newDispatcher) { using Decoration = DefaultDecoration> >>; return ContinuableBase(Decoration({ - std::move(data.ownership), - std::move(data.continuation), + std::move(undecorated.ownership), + std::move(undecorated.continuation), std::forward(newDispatcher) })); } @@ -609,49 +613,4 @@ struct FailIfWrongArgs { -> std::enable_if_t { } }; -int main(int, char**) { - auto dispatcher = SelfDispatcher{}; - - /*(makeTestContinuation() && makeTestContinuation()) - .undecorateFor([]() - { - - });*/ - - /*auto unwrapper = [](auto&&... args) { - return std::common_type>{}; - };*/ - - // using T = decltype(unwrap(FailIfWrongArgs<0>{})); - - // using T = decltype(unwrap(std::declval())); - // T t{}; - - // auto combined = makeTestContinuation() && makeTestContinuation(); - - int res = 0; - makeTestContinuation() - .then([](std::string) { - return std::make_tuple(47, 46, 45); - }) - // .post(dispatcher) - .then([](int val1, int val2, int val3) { - return val1 + val2 + val3; - }) - .then([&](int val) { - res += val; - }) - .then([] { - - - - return makeTestContinuation(); - }) - .then([] (std::string arg) { - - }); - - return res; -} - #endif // CONTINUABLE_HPP_INCLUDED__ diff --git a/incubator.cpp b/incubator.cpp index e69de29..e9b2e19 100644 --- a/incubator.cpp +++ b/incubator.cpp @@ -0,0 +1,55 @@ + +#include + +#include "continuable/continuable.hpp" + +template +using continuable = decltype(make_continuable(std::declval>)); + +int main(int, char**) { + // continuable c; + + auto dispatcher = SelfDispatcher{}; + + /*(makeTestContinuation() && makeTestContinuation()) + .undecorateFor([]() + { + + });*/ + + /*auto unwrapper = [](auto&&... args) { + return std::common_type>{}; + };*/ + + // using T = decltype(unwrap(FailIfWrongArgs<0>{})); + + // using T = decltype(unwrap(std::declval())); + // T t{}; + + // auto combined = makeTestContinuation() && makeTestContinuation(); + + int res = 0; + makeTestContinuation() + .then([](std::string) { + return std::make_tuple(47, 46, 45); + }) + // .post(dispatcher) + .then([](int val1, int val2, int val3) { + return val1 + val2 + val3; + }) + .then([&](int val) { + res += val; + }) + .then([] { + + + + return makeTestContinuation(); + }) + .then(makeTestContinuation()) + .then([] (std::string arg) { + + }); + + return res; +}