From 591592385a9dec81a66f28fa3bf284ccc8849501 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Thu, 13 Oct 2016 00:48:25 +0200 Subject: [PATCH] Generalize undecorators with an undecorator function --- include/continuable/continuable.hpp | 43 +++++++++++++++++++---------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/include/continuable/continuable.hpp b/include/continuable/continuable.hpp index 42cb627..8dfbf4d 100644 --- a/include/continuable/continuable.hpp +++ b/include/continuable/continuable.hpp @@ -352,7 +352,8 @@ void invokeContinuation(Data data) { } } -/// +/// Holds the effective data for the continuable, like the current owner status, +/// the continuation object and the dispatcher. template struct ContinuableData { @@ -396,29 +397,40 @@ struct ContinuableData { Dispatcher dispatcher; }; -/// The DefaultDecoration is a container for already materialized -/// ContinuableData which can be accessed instantly. -template -class DefaultDecoration { +/// An undecorator that undecorates nothing +struct UndecorateNone { + template + static auto undecorate(T&& data) -> std::decay_t { + return std::forward(data); + } +}; + +/// The Undecorateable is a container for unmaterialized +/// ContinuableData which can be accessed on demand. +template +class Undecorateable { public: - explicit DefaultDecoration(Data data_) + explicit Undecorateable(Data data_) : data(std::move(data_)) { } /// Return a r-value reference to the data - template - Data&& undecorate()&& { - return std::move(data); + template + auto undecorate()&& { + return Undecorator::template undecorate(std::move(data)); } + /// Return a copy of the data - template - Data undecorate() const& { - return data; + template + auto undecorate() const& { + return Undecorator::template undecorate(data); } private: Data data; }; + template auto undecorateCombined(Identity, std::tuple combined) { @@ -431,6 +443,7 @@ auto undecorateCombined(std::tuple combined) { // return undecorateCombined(TargetArgs{}, std::move(combined)); } +// FIXME template class LazyCombineDecoration { public: @@ -477,7 +490,7 @@ private: template auto make_continuable(Continuation&& continuation, Dispatcher&& dispatcher = SelfDispatcher{}) noexcept { - using Decoration = DefaultDecoration, std::decay_t >>; @@ -491,7 +504,7 @@ template auto thenImpl(Undecorated undecorated, Callback&& callback) { auto next = appendCallback(std::move(undecorated.continuation), std::forward(callback)); - using Decoration = DefaultDecoration< + using Decoration = Undecorateable< typename Undecorated::template ChangeContinuationTo >; return ContinuableBase(Decoration({ @@ -503,7 +516,7 @@ auto thenImpl(Undecorated undecorated, Callback&& callback) { template auto postImpl(Undecorated undecorated, NewDispatcher&& newDispatcher) { - using Decoration = DefaultDecoration< + using Decoration = Undecorateable< typename Undecorated::template ChangeDispatcherTo> >;