diff --git a/examples/example-asio/example-asio.cpp b/examples/example-asio/example-asio.cpp index 83bfd3c..5145ff9 100644 --- a/examples/example-asio/example-asio.cpp +++ b/examples/example-asio/example-asio.cpp @@ -50,7 +50,7 @@ inline auto error_code_remapper() { #if defined(CONTINUABLE_HAS_EXCEPTIONS) promise.set_exception(std::make_exception_ptr(e)); #else - promise.set_exception(cti::error_type(e.value(), e.category())); + promise.set_exception(cti::exception_t(e.value(), e.category())); #endif } else { promise.set_value(std::forward(args)...); @@ -108,7 +108,7 @@ int main(int, char**) { // auto socket = std::make_shared(service); // socket->async_send_to() }) - .fail([](cti::error_type /*error*/) { + .fail([](cti::exception_t /*error*/) { // ... }); diff --git a/include/continuable/continuable-base.hpp b/include/continuable/continuable-base.hpp index ff5afd4..de91679 100644 --- a/include/continuable/continuable-base.hpp +++ b/include/continuable/continuable-base.hpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -55,41 +56,6 @@ namespace cti { /// provides classes and functions to create continuable_base objects. /// \{ -/// Represents a tag which can be placed first in a signature -/// in order to overload callables with the asynchronous result -/// as well as an error. -/// -/// See the example below: -/// ```cpp -/// struct my_callable { -/// void operator() (std::string result) { -/// // ... -/// } -/// void operator() (cti::dispatch_error_tag, cti::error_type) { -/// // ... -/// } -/// }; -/// -/// // Will receive errors and results -/// continuable.next(my_callable{}); -/// ``` -/// -/// \note see continuable::next for details. -/// -/// \since 2.0.0 -using dispatch_error_tag = detail::types::dispatch_error_tag; - -/// Represents the type that is used as error type -/// -/// By default this type deduces to `std::exception_ptr`. -/// If `CONTINUABLE_WITH_NO_EXCEPTIONS` is defined the type -/// will be a `std::error_condition`. -/// A custom error type may be set through -/// defining `CONTINUABLE_WITH_CUSTOM_ERROR_TYPE`. -/// -/// \since 2.0.0 -using error_type = detail::types::error_type; - /// Deduces to a true_type if the given type is a continuable_base. /// /// \since 3.0.0 @@ -371,8 +337,10 @@ public: template auto fail(continuable_base&& continuation) && { continuation.freeze(); - return std::move(*this).fail([continuation = std::move(continuation)]( - error_type) mutable { std::move(continuation).done(); }); + return std::move(*this).fail( + [continuation = std::move(continuation)](exception_t) mutable { + std::move(continuation).done(); + }); } /// A method which allows to use an overloaded callable for the error @@ -386,7 +354,7 @@ public: /// void operator() (std::string result) { /// // ... /// } - /// void operator() (cti::dispatch_error_tag, cti::error_type) { + /// void operator() (cti::exception_arg_t, cti::exception_t) { /// // ... /// } /// @@ -658,7 +626,7 @@ public: /// if (auto&& result = co_await http_request("github.com")) { /// auto value = *result; /// } else { - /// cti::error_type error = result.get_exception(); + /// cti::exception_t error = result.get_exception(); /// } /// /// auto result = co_await http_request("github.com"); diff --git a/include/continuable/continuable-primitives.hpp b/include/continuable/continuable-primitives.hpp new file mode 100644 index 0000000..ce3b688 --- /dev/null +++ b/include/continuable/continuable-primitives.hpp @@ -0,0 +1,128 @@ + +/* + + /~` _ _ _|_. _ _ |_ | _ + \_,(_)| | | || ||_|(_||_)|(/_ + + https://github.com/Naios/continuable + v3.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_PRIMITIVES_HPP_INCLUDED +#define CONTINUABLE_PRIMITIVES_HPP_INCLUDED + +#include + +namespace cti { +/// \defgroup Primitives Primitives +/// provides basic tag types for creating a customized callbacks +/// and continuations. +/// For the callback and the continuation `Args...` represents the +/// asynchronous results: +/// ```cpp +/// template +/// struct continuation { +/// void operator() (callback); +/// bool operator() (cti::is_ready_arg_t) const; +/// std::tuple operator() (cti::get_arg_t); +/// }; +/// template +/// struct continuation { +/// template +/// void operator() (callback); +/// bool operator() (cti::is_ready_arg_t) const; +/// T operator() (cti::get_arg_t); +/// }; +/// template<> +/// struct continuation { +/// void operator() (callback<>); +/// bool operator() (cti::is_ready_arg_t) const; +/// void operator() (cti::get_arg_t); +/// }; +/// ``` +/// ```cpp +/// template +/// struct callback { +/// void operator() (Args...); +/// void operator() (cti::exception_arg_t, cti::exception_t); +/// }; +/// ``` +/// \{ + +/// 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. +/// +/// \since 4.0.0 +struct is_ready_arg_t {}; + +/// Represents the tag type that is used to query the continuation +/// for its arguments when resolves the callback instantly +/// without having side effects. +/// It's required that the query of is_ready_arg_t returns true. +/// +/// \since 4.0.0 +struct get_arg_t {}; + +/// Represents the tag type that is used to disambiguate the +/// callback operator() in order to take the exception asynchronous chain. +/// +/// \note see continuable::next for details. +/// +/// \since 4.0.0 +struct exception_arg_t {}; + +/// \copydoc exception_arg_t +/// +/// \deprecated The exception_arg_t was deprecated in order to move closer +/// to the types specified in the "A Unified Future" proposal +/// especially regarding naming types similar. +/// +[[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; + +/// Represents the type that is used as exception type +/// +/// By default this type deduces to `std::exception_ptr`. +/// If `CONTINUABLE_WITH_NO_EXCEPTIONS` is defined the type +/// will be a `std::error_condition`. +/// A custom error type may be set through +/// defining `CONTINUABLE_WITH_CUSTOM_ERROR_TYPE`. +/// +/// \since 4.0.0 +using exception_t = detail::types::exception_t; + +/// \copydoc exception_t +/// +/// \deprecated The exception_t was deprecated in order to move closer +/// to the types specified in the "A Unified Future" proposal +/// especially regarding naming types similar. +/// +[[deprecated("The error_type was replaced by exception_t and will " + "be removed in a later major version!")]] // +typedef exception_t error_type; +/// \} +} // namespace cti + +#endif // CONTINUABLE_PRIMITIVES_HPP_INCLUDED diff --git a/include/continuable/continuable-promise-base.hpp b/include/continuable/continuable-promise-base.hpp index ce8401e..298fd5b 100644 --- a/include/continuable/continuable-promise-base.hpp +++ b/include/continuable/continuable-promise-base.hpp @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -50,7 +51,7 @@ namespace cti { /// /// If we want to resolve the promise_base trough the call operator, /// and we want to resolve it through an exception, we must call it with a -/// dispatch_error_tag as first and the exception as second argument. +/// exception_arg_t as first and the exception as second argument. /// Additionally the promise is resolveable only through its call /// operator when invoked as an r-value. /// @@ -100,8 +101,8 @@ public: /// \throws This method never throws an exception. /// /// \since 2.0.0 - void operator()(detail::types::dispatch_error_tag tag, - detail::types::error_type exception) && + void operator()(exception_arg_t tag, + exception_t exception) && noexcept { std::move(data_)(tag, std::move(exception)); } @@ -120,8 +121,8 @@ public: /// \throws This method never throws an exception. /// /// \since 2.0.0 - void set_exception(detail::types::error_type exception) noexcept { - std::move(data_)(detail::types::dispatch_error_tag{}, std::move(exception)); + void set_exception(exception_t exception) noexcept { + std::move(data_)(exception_arg_t{}, std::move(exception)); } }; /// \} diff --git a/include/continuable/continuable-trait.hpp b/include/continuable/continuable-trait.hpp index c104115..b30e5dd 100644 --- a/include/continuable/continuable-trait.hpp +++ b/include/continuable/continuable-trait.hpp @@ -32,6 +32,7 @@ #define CONTINUABLE_TRAIT_HPP_INCLUDED #include +#include #include #include #include @@ -60,8 +61,8 @@ template