From b4a622047c55b374267cdcf113df22a3006f62ab Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Mon, 24 Oct 2016 19:11:18 +0200 Subject: [PATCH] more --- include/continuable/continuable.hpp | 105 ++++++++++++++++------------ incubator.cpp | 6 ++ 2 files changed, 68 insertions(+), 43 deletions(-) diff --git a/include/continuable/continuable.hpp b/include/continuable/continuable.hpp index 24ac737..6e4adaa 100644 --- a/include/continuable/continuable.hpp +++ b/include/continuable/continuable.hpp @@ -142,13 +142,13 @@ struct Identity { }; template class ContinuableBase; -static auto createEmptyContinuation() { - return [](auto&& callback) { callback(); }; +template +void emptyContinuation(T&& callback) { + std::forward(callback)(); } -static auto createEmptyCallback() { - return [](auto&&...) { }; -} +template +void emptyCallback(Args&&... /*arguments*/) { } template auto applyTuple(std::integer_sequence, T&& tuple, F&& function) { @@ -205,59 +205,83 @@ private: }; template -struct SignatureHint : std::true_type { - typedef Identity argument_type; +struct ArgumentsHint : std::true_type { + /// The argument types of the function as pack in Identity. + using argument_type = Identity; +}; + +template +struct ArgumentsHint : std::true_type { + /// The argument types of the function as pack in Identity. + using argument_type = Identity; + + using only_argument_type = OnlyArgument; }; template<> -struct SignatureHint : std::false_type { }; +struct ArgumentsHint : std::false_type { }; -using AbsentSignatureHint = SignatureHint; - -template -using InferSignatureFrom = AbsentSignatureHint; +using AbsentArgumentsHint = ArgumentsHint; template -struct undecorate_function; +struct GetArgumentsHint; template -struct undecorate_function { - /// The return type of the function. - typedef ReturnType return_type; - /// The argument types of the function as pack in Identity. - typedef Identity argument_type; -}; +struct GetArgumentsHint + : std::common_type> { }; /// Mutable function pointers template -struct undecorate_function - : undecorate_function { }; +struct GetArgumentsHint + : GetArgumentsHint { }; /// Const function pointers template -struct undecorate_function - : undecorate_function { }; +struct GetArgumentsHint + : GetArgumentsHint { }; /// Mutable class method pointers template -struct undecorate_function - : undecorate_function { }; +struct GetArgumentsHint + : GetArgumentsHint { }; /// Const class method pointers template -struct undecorate_function - : undecorate_function { }; +struct GetArgumentsHint + : GetArgumentsHint { }; /// Mutable volatile class method pointers template -struct undecorate_function - : undecorate_function { }; +struct GetArgumentsHint + : GetArgumentsHint { }; /// Const volatile class method pointers template -struct undecorate_function - : undecorate_function { }; +struct GetArgumentsHint + : GetArgumentsHint { }; +template class Accept> +struct invocation_acceptor_select + >()(std::declval()...)), + ReturnType + >::value>::type>> + : Accept<>{}; + +template> +struct InferArgumentsFromType : AbsentArgumentsHint { }; + +template +using InferArgumentsFrom = typename InferArgumentsFromType::type; + +/* template using do_undecorate = std::conditional_t< std::is_class::value, @@ -271,6 +295,7 @@ template struct is_undecorateable::return_type >> : std::true_type { }; +*/ /// Decorates single values template @@ -279,7 +304,7 @@ struct CallbackResultDecorator { static auto decorate(Callback&& callback) { return [callback = std::forward(callback)](auto&&... args) { Value value = callback(std::forward(args)...); - return [value = std::move(value)](auto&& callback) mutable { + return [value = std::move(value)](auto&& callback) mutable { callback(std::move(value)); }; }; @@ -302,7 +327,7 @@ struct CallbackResultDecorator { static auto decorate(Callback&& callback) { return [callback = std::forward(callback)](auto&&... args) { callback(std::forward(args)...); - return createEmptyContinuation(); + return emptyContinuation; }; } }; @@ -361,7 +386,7 @@ void invokeContinuation(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)(createEmptyCallback()); + std::move(data.continuation)(emptyCallback); } } @@ -369,7 +394,7 @@ void invokeContinuation(Data data) { /// the continuation object and the dispatcher. template> + typename ArgumentsHintType = InferArgumentsFrom> struct ContinuableData { /// The plain continuation type that is stored within the data. /// Continuation types have a templated or a fixed signature @@ -384,7 +409,7 @@ struct ContinuableData { /// TODO using Dispatcher = DispatcherType; /// The possible signature hint of the continuation - using SignatureHint = SignatureHintType; + using ArgumentsHint = ArgumentsHintType; ContinuableData(Continuation continuation_, Dispatcher dispatcher_) noexcept @@ -405,7 +430,7 @@ struct ContinuableData { template using ChangeDispatcherTo = ContinuableData< - Continuation, NewType, SignatureHint + Continuation, NewType, ArgumentsHint >; Ownership ownership; @@ -625,12 +650,6 @@ private: Decoration decoration; }; -static auto makeTestContinuation() { - return make_continuable([i = std::make_unique(0)](auto&& callback) { - callback("47"); - }); -} - struct Inspector { template auto operator() (Args...) { diff --git a/incubator.cpp b/incubator.cpp index e9b2e19..736bd47 100644 --- a/incubator.cpp +++ b/incubator.cpp @@ -6,6 +6,12 @@ template using continuable = decltype(make_continuable(std::declval>)); +static auto makeTestContinuation() { + return make_continuable([i = std::make_unique(0)](auto&& callback) { + callback("47"); + }); +} + int main(int, char**) { // continuable c;