From 1cbfcbea6dbb42e06c322323467f3e8cfcbdb601 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Tue, 25 Dec 2018 09:57:14 +0100 Subject: [PATCH] Use new types instead of aliases for type erasure * Makes compiler output much more readable --- include/continuable/continuable-types.hpp | 58 ++++++++++++++--------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/include/continuable/continuable-types.hpp b/include/continuable/continuable-types.hpp index f5566f8..ab0f9a2 100644 --- a/include/continuable/continuable-types.hpp +++ b/include/continuable/continuable-types.hpp @@ -41,27 +41,45 @@ namespace cti { /// cti::promise promise\endlink facility for type erasure. /// \{ -// clang-format off namespace detail { -/// A function which isn't size adjusted and move only -template -using unique_function_adapter = fu2::unique_function; +/// A type erasure which isn't size adjusted and move only +template +class type_erasure : public fu2::unique_function { +public: + using fu2::unique_function::unique_function; + using fu2::unique_function::operator=; + using fu2::unique_function::operator(); +}; + /// A function which is size adjusted and move only -template -using unique_function_adjustable = fu2::function_base; +template +class sized_type_erasure + : public fu2::function_base { + +public: + using fu2::function_base::function_base; + using fu2::function_base::operator=; + using fu2::function_base::operator(); +}; /// We adjust the internal capacity of the outer function wrapper so /// we don't have to allocate twice when using `continuable<...>`. -template -using unique_trait_of = continuable_trait< - unique_function_adapter, - unique_function_adjustable, - Args... ->; +template +using unique_trait_of = continuable_trait< // + type_erasure, sized_type_erasure, + Args... // + >; /// A type erasure for work objects -using work = fu2::unique_function; +class work_type_erasure : public fu2::unique_function { +public: + using fu2::unique_function::unique_function; + using fu2::unique_function::operator=; + using fu2::unique_function::operator(); +}; } // namespace detail /// Defines a non-copyable continuation type which uses the @@ -69,29 +87,23 @@ using work = fu2::unique_function; /// /// Usable like: `continuable` template -using continuable = typename detail::unique_trait_of< - Args... ->::continuable; +using continuable = typename detail::unique_trait_of::continuable; /// Defines a non-copyable promise type which is using the /// function2 backend for type erasure. /// /// Usable like: `promise` template -using promise = typename detail::unique_trait_of< - Args... ->::promise; +using promise = typename detail::unique_trait_of::promise; /// Defines a non-copyable type erasure which is capable of carrying /// callable objects passed to executors. /// /// \since 4.0.0 -using work = detail::work; +using work = detail::work_type_erasure; // TODO channel // TODO sink - -// clang-format on /// \} } // namespace cti