From c066940d8d47f0de7af73f7130c00aa79848dfec Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Fri, 4 Jan 2019 00:09:26 +0100 Subject: [PATCH] Use new types instead of aliases for type erasures * Makes compiler output much more readable This is configurateable through CONTINUABLE_WITH_IMMEDIATE_TYPES, and automatically enabled for debug builds but disabled for release builds. * Remove the old continuable-trait.hpp header * Make the signature of continuable not dependent anymore on any size of the arguments which fixes the compilation with forward declared types. Thanks Rogiel for the correspoding bug report. Closes #11 --- .travis.yml | 3 + appveyor.yml | 9 +- doc/Doxyfile | 4 +- doc/changelog.dox | 2 +- doc/configuration.dox | 1 + include/continuable/continuable-base.hpp | 20 +- include/continuable/continuable-coroutine.hpp | 2 +- .../continuable/continuable-primitives.hpp | 18 +- .../continuable/continuable-promise-base.hpp | 8 +- include/continuable/continuable-testing.hpp | 2 +- include/continuable/continuable-trait.hpp | 89 --------- include/continuable/continuable-types.hpp | 80 ++++---- include/continuable/continuable.hpp | 1 - .../connection/connection-aggregated.hpp | 26 +-- .../detail/connection/connection-any.hpp | 18 +- .../continuable/detail/core/annotation.hpp | 6 +- include/continuable/detail/core/base.hpp | 132 ++++++------- include/continuable/detail/core/types.hpp | 1 + include/continuable/detail/features.hpp | 12 ++ .../continuable/detail/other/coroutines.hpp | 4 +- include/continuable/detail/other/erasure.hpp | 180 ++++++++++++++++++ include/continuable/detail/other/testing.hpp | 6 +- .../continuable/detail/other/transforms.hpp | 4 +- .../detail/utility/flat-variant.hpp | 4 +- .../continuable/detail/utility/identity.hpp | 54 ++++++ include/continuable/detail/utility/traits.hpp | 14 +- test/unit-test/CMakeLists.txt | 2 + .../multi/test-continuable-base-errors.cpp | 2 +- .../single/test-continuable-erasure.cpp | 89 +++++++++ .../single/test-continuable-forward-decl.cpp | 31 +++ test/unit-test/test-continuable.hpp | 16 +- tools/travis-ci.sh | 2 +- 32 files changed, 568 insertions(+), 274 deletions(-) delete mode 100644 include/continuable/continuable-trait.hpp create mode 100644 include/continuable/detail/other/erasure.hpp create mode 100644 include/continuable/detail/utility/identity.hpp create mode 100644 test/unit-test/single/test-continuable-erasure.cpp create mode 100644 test/unit-test/single/test-continuable-forward-decl.cpp diff --git a/.travis.yml b/.travis.yml index c28618c..7bd1768 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ matrix: - ninja-build env: - COMPILER=g++-6 + - BUILD_CONFIG=Debug - WITH_NO_EXCEPTIONS=OFF - WITH_AWAIT=OFF - WITH_LIGHT_TESTS=ON @@ -36,6 +37,7 @@ matrix: - ninja-build env: - COMPILER=clang++-5.0 + - BUILD_CONFIG=Release - WITH_NO_EXCEPTIONS=OFF - WITH_AWAIT=OFF - WITH_LIGHT_TESTS=OFF @@ -52,6 +54,7 @@ matrix: - ninja-build env: - COMPILER=clang++-5.0 + - BUILD_CONFIG=Debug - WITH_NO_EXCEPTIONS=ON - WITH_AWAIT=ON - WITH_LIGHT_TESTS=ON diff --git a/appveyor.yml b/appveyor.yml index 99d1aca..51d9885 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,11 +3,14 @@ image: environment: matrix: - - WITH_NO_EXCEPTIONS: OFF + - CONFIGURATION: Debug + WITH_NO_EXCEPTIONS: OFF WITH_CPP_LATEST: OFF - - WITH_NO_EXCEPTIONS: ON + - CONFIGURATION: Debug + WITH_NO_EXCEPTIONS: ON WITH_CPP_LATEST: OFF - - WITH_NO_EXCEPTIONS: OFF + - CONFIGURATION: Release + WITH_NO_EXCEPTIONS: OFF WITH_CPP_LATEST: ON configuration: diff --git a/doc/Doxyfile b/doc/Doxyfile index da626db..d0f1c7a 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -38,13 +38,13 @@ PROJECT_NAME = Continuable # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 3.0.0 +PROJECT_NUMBER = 4.0.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a # quick idea about the purpose of the project. Keep the description short. -PROJECT_BRIEF = +PROJECT_BRIEF = "C++14 asynchronous allocation aware futures" # With the PROJECT_LOGO tag one can specify a logo or an icon that is included # in the documentation. The maximum height of the logo should not exceed 55 diff --git a/doc/changelog.dox b/doc/changelog.dox index 60c4133..c80c791 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -41,7 +41,7 @@ New helper functions were added to create ready continuables: The implementation of connections were rewritten entirely. It is possible now to connect runtime sized containers as well as -deeply nested sequences. See \ref tutorial-connections for details. +deeply nested sequences. See \ref tutorial-connecting-continuables for details. Additionally connection overloads were added that accept two iterators in order to come closer to the interface of the standard library. diff --git a/doc/configuration.dox b/doc/configuration.dox index ce7fb15..7174603 100644 --- a/doc/configuration.dox +++ b/doc/configuration.dox @@ -34,6 +34,7 @@ in order to change the libraries behaviour: | `CONTINUABLE_WITH_CUSTOM_ERROR_TYPE` | Exceptions are disabled and the type defined by `CONTINUABLE_WITH_CUSTOM_ERROR_TYPE` is used as \ref error_type . See \ref tutorial-chaining-continuables-fail for details. | | `CONTINUABLE_WITH_UNHANDLED_EXCEPTIONS` | Allows unhandled exceptions in asynchronous call hierarchies. See \ref tutorial-chaining-continuables-fail for details. | | `CONTINUABLE_WITH_CUSTOM_FINAL_CALLBACK` | Allows to customize the final callback which can be used to implement custom unhandled asynchronous exception handlers. | +| `CONTINUABLE_WITH_IMMEDIATE_TYPES` | Don't decorate the used type erasure, which is done to keep type names minimal for better error messages in debug builds. | | `CONTINUABLE_WITH_EXPERIMENTAL_COROUTINE` | Enables support for experimental coroutines and `co_await` expressions. See \ref continuable_base::operator co_await() for details. | */ diff --git a/include/continuable/continuable-base.hpp b/include/continuable/continuable-base.hpp index 9f88907..4b73274 100644 --- a/include/continuable/continuable-base.hpp +++ b/include/continuable/continuable-base.hpp @@ -123,19 +123,31 @@ public: std::enable_if_t>::value>* = nullptr> - continuable_base(OtherData&& data) + /* implicit */ continuable_base(OtherData&& data) : data_(detail::base::proxy_continuable< Annotation, detail::traits::unrefcv_t>( std::forward(data))) { } + /// Constructor taking the data of other continuable_base objects + /// while erasing the hint. + /// + /// This constructor makes it possible to replace the internal data object of + /// the continuable by any object which is useful for type-erasure. + /*template , Data>::value>* = nullptr> +continuable_base(continuable_base&& other) + : continuable_base(std::move(other).consume()) { + }*/ + /// Constructor taking the data of other continuable_base objects /// while erasing the hint. /// /// This constructor makes it possible to replace the internal data object of /// the continuable by any object which is useful for type-erasure. template - continuable_base(continuable_base&& other) + /* implicit */ continuable_base(continuable_base&& other) : continuable_base(std::move(other).finish().consume()) { } @@ -853,7 +865,7 @@ constexpr auto make_continuable(Continuation&& continuation) { template auto make_ready_continuable(Args&&... args) { using detail::base::ready_continuation; - using detail::traits::identity; + using detail::identity; using detail::traits::unrefcv_t; return detail::base::attorney::create_from_raw( ready_continuation...>{std::forward(args)...}, @@ -932,7 +944,7 @@ auto make_cancelling_continuable() { /// // Recovered from the failure /// }) /// ``` -/// A corresponding \ref result is returned by \ref recover: +/// A corresponding \ref result is returned by \ref recover /// ```cpp /// http_request("example.com") /// .then([](std::string content) -> cti::result { diff --git a/include/continuable/continuable-coroutine.hpp b/include/continuable/continuable-coroutine.hpp index fdd21fd..ee1680d 100644 --- a/include/continuable/continuable-coroutine.hpp +++ b/include/continuable/continuable-coroutine.hpp @@ -51,7 +51,7 @@ namespace std { namespace experimental { template struct coroutine_traits< - cti::continuable_base>, + cti::continuable_base>, FunctionArgs...> { using promise_type = diff --git a/include/continuable/continuable-primitives.hpp b/include/continuable/continuable-primitives.hpp index 054eb11..771a2dc 100644 --- a/include/continuable/continuable-primitives.hpp +++ b/include/continuable/continuable-primitives.hpp @@ -32,6 +32,7 @@ #define CONTINUABLE_PRIMITIVES_HPP_INCLUDED #include +#include namespace cti { /// \defgroup Primitives Primitives @@ -50,12 +51,19 @@ namespace cti { /// ```cpp /// template /// struct callback { -/// void operator() (Args...); -/// void operator() (cti::exception_arg_t, cti::exception_t); +/// void operator() (Args...) &&; +/// void operator() (cti::exception_arg_t, cti::exception_t) &&; /// }; /// ``` /// \{ +/// Represents the tag type that is used to specify the signature hint +/// of a continuable_base or promise_base. +/// +/// \since 4.0.0 +template +using signature_arg_t = detail::identity; + /// Represents the tag type that is used to query the continuation /// for whether it resolves the callback instantly with its arguments /// without having side effects. @@ -69,7 +77,7 @@ struct is_ready_arg_t {}; /// It's required that the query of is_ready_arg_t returns true. /// /// \since 4.0.0 -struct query_arg_t {}; +struct query_arg_t { }; /// Represents the tag type that is used to disambiguate the /// callback operator() in order to take the exception asynchronous chain. @@ -87,7 +95,7 @@ struct exception_arg_t {}; /// [[deprecated("The dispatch_error_tag was replaced by exception_arg_t and will " "be removed in a later major version!")]] // -typedef exception_arg_t dispatch_error_tag; + typedef exception_arg_t dispatch_error_tag; /// Represents the type that is used as exception type /// @@ -108,7 +116,7 @@ using exception_t = detail::types::exception_t; /// [[deprecated("The error_type was replaced by exception_t and will " "be removed in a later major version!")]] // -typedef exception_t error_type; + typedef exception_t error_type; /// \} } // namespace cti diff --git a/include/continuable/continuable-promise-base.hpp b/include/continuable/continuable-promise-base.hpp index fa4780f..38d2e3d 100644 --- a/include/continuable/continuable-promise-base.hpp +++ b/include/continuable/continuable-promise-base.hpp @@ -36,6 +36,7 @@ #include #include #include +#include #include namespace cti { @@ -62,7 +63,7 @@ class promise_base /// \cond false ; template -class promise_base> +class promise_base> : detail::util::non_copyable /// \endcond { // clang-format on @@ -83,8 +84,9 @@ public: /// \endcond /// Constructor accepting any object convertible to the data object - template , Data>::value>* = nullptr> + template , Data>::value>* = nullptr> promise_base(OData&& data) : data_(std::forward(data)) { } diff --git a/include/continuable/continuable-testing.hpp b/include/continuable/continuable-testing.hpp index df9847a..34e8710 100644 --- a/include/continuable/continuable-testing.hpp +++ b/include/continuable/continuable-testing.hpp @@ -158,7 +158,7 @@ /// \since 1.0.0 #define ASSERT_ASYNC_TYPES(CONTINUABLE, ...) \ cti::detail::testing::assert_async_types( \ - CONTINUABLE, cti::detail::traits::identity<__VA_ARGS__>{}) + CONTINUABLE, cti::detail::identity<__VA_ARGS__>{}) /// Asserts that the continuable is finished with the given exception /// diff --git a/include/continuable/continuable-trait.hpp b/include/continuable/continuable-trait.hpp deleted file mode 100644 index 7d42080..0000000 --- a/include/continuable/continuable-trait.hpp +++ /dev/null @@ -1,89 +0,0 @@ - -/* - - /~` _ _ _|_. _ _ |_ | _ - \_,(_)| | | || ||_|(_||_)|(/_ - - https://github.com/Naios/continuable - v4.0.0 - - Copyright(c) 2015 - 2018 Denis Blank - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files(the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and / or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions : - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -**/ - -#ifndef CONTINUABLE_TRAIT_HPP_INCLUDED -#define CONTINUABLE_TRAIT_HPP_INCLUDED - -#include -#include -#include -#include -#include -#include -#include - -namespace cti { -/// \defgroup Types Types -/// provides the \link cti::continuable continuable\endlink and \link -/// cti::promise promise\endlink facility for type erasure. -/// \{ - -/// Trait to retrieve a continuable_base type with a given type-erasure backend. -/// -/// Every object may me used as type-erasure backend as long as the -/// requirements of a `std::function` like wrapper are satisfied. -/// -/// \tparam CallbackWrapper The type which is used to erase the callback. -/// -/// \tparam ContinuationWrapper The type which is used to erase the -/// continuation data. -/// -/// \tparam Args The current signature of the continuable. -template