From ec15592bca721123de35268cbc78043dd88aaa5a Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Thu, 13 Oct 2016 00:26:14 +0200 Subject: [PATCH] Merge the continuable data with the config --- include/continuable/continuable.hpp | 74 +++++++++++++++-------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/include/continuable/continuable.hpp b/include/continuable/continuable.hpp index 9c2eb46..42cb627 100644 --- a/include/continuable/continuable.hpp +++ b/include/continuable/continuable.hpp @@ -352,42 +352,48 @@ void invokeContinuation(Data data) { } } -template -struct ContinuableConfig { +/// +template +struct ContinuableData { + /// The plain continuation type that is stored within the data. + /// Continuation types have a templated or a fixed signature + /// where `operator()` expects one variable that has the following + /// `operator()` signature: `void()` callback args + /// For instance: + /// std::function)> + /// ^^^^^^^^ ^^^^^^^^ + /// continuation callback + /// where int and float are the arguments the callback is invoked with. using Continuation = ContinuationType; + /// TODO using Dispatcher = DispatcherType; - template - using ChangeContinuationTo = ContinuableConfig< - NewType, Dispatcher - >; - - template - using ChangeDispatcherTo = ContinuableConfig< - Continuation, NewType - >; -}; - -/// -template -struct ContinuableData { - using Config = ConfigType; + ContinuableData(Continuation continuation_, + Dispatcher dispatcher_) noexcept + : continuation(std::move(continuation_)), + dispatcher(std::move(dispatcher_)) { } ContinuableData(Ownership ownership_, - typename Config::Continuation continuation_, - typename Config::Dispatcher dispatcher_) noexcept + Continuation continuation_, + Dispatcher dispatcher_) noexcept : ownership(std::move(ownership_)), continuation(std::move(continuation_)), dispatcher(std::move(dispatcher_)) { } - ContinuableData(typename Config::Continuation continuation_, - typename Config::Dispatcher dispatcher_) noexcept - : continuation(std::move(continuation_)), - dispatcher(std::move(dispatcher_)) { } + template + using ChangeContinuationTo = ContinuableData< + NewType, Dispatcher + >; + + template + using ChangeDispatcherTo = ContinuableData< + Continuation, NewType + >; Ownership ownership; - typename Config::Continuation continuation; - typename Config::Dispatcher dispatcher; + Continuation continuation; + Dispatcher dispatcher; }; /// The DefaultDecoration is a container for already materialized @@ -398,8 +404,6 @@ public: explicit DefaultDecoration(Data data_) : data(std::move(data_)) { } - using Config = typename Data::Config; - /// Return a r-value reference to the data template Data&& undecorate()&& { @@ -473,10 +477,10 @@ private: template auto make_continuable(Continuation&& continuation, Dispatcher&& dispatcher = SelfDispatcher{}) noexcept { - using Decoration = DefaultDecoration, std::decay_t - >>>; + >>; return ContinuableBase(Decoration({ std::forward(continuation), std::forward(dispatcher) @@ -487,9 +491,9 @@ template auto thenImpl(Undecorated undecorated, Callback&& callback) { auto next = appendCallback(std::move(undecorated.continuation), std::forward(callback)); - using Decoration = DefaultDecoration - >>; + using Decoration = DefaultDecoration< + typename Undecorated::template ChangeContinuationTo + >; return ContinuableBase(Decoration({ std::move(undecorated.ownership), std::move(next), @@ -499,10 +503,10 @@ auto thenImpl(Undecorated undecorated, Callback&& callback) { template auto postImpl(Undecorated undecorated, NewDispatcher&& newDispatcher) { - using Decoration = DefaultDecoration> - >>; + >; return ContinuableBase(Decoration({ std::move(undecorated.ownership), std::move(undecorated.continuation),