Simplify make_exceptional_continuable

This commit is contained in:
Denis Blank 2018-02-27 17:18:52 +01:00
parent 9c087e60d2
commit 2cbac4da98

View File

@ -47,6 +47,41 @@
#include <continuable/detail/util.hpp> #include <continuable/detail/util.hpp>
namespace cti { namespace cti {
/// 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 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 detail::types::error_type;
/// Deduces to a true_type if the given type is a continuable_base. /// Deduces to a true_type if the given type is a continuable_base.
/// ///
/// \since 3.0.0 /// \since 3.0.0
@ -329,7 +364,7 @@ public:
auto fail(continuable_base<OData, OAnnotation>&& continuation) && { auto fail(continuable_base<OData, OAnnotation>&& continuation) && {
continuation.freeze(); continuation.freeze();
return std::move(*this).fail([continuation = std::move(continuation)]( return std::move(*this).fail([continuation = std::move(continuation)](
detail::types::error_type) mutable { std::move(continuation).done(); }); error_type) mutable { std::move(continuation).done(); });
} }
/// A method which allows to use an overloaded callable for the error /// A method which allows to use an overloaded callable for the error
@ -771,49 +806,14 @@ constexpr auto make_ready_continuable(FirstResult&& first_result,
/// returned continuable. /// returned continuable.
/// ///
/// \since 3.0.0 /// \since 3.0.0
template <typename Exception, typename FirstArg = void, typename... Rest> template <typename FirstArg = void, typename... Rest>
constexpr auto make_exceptional_continuable(Exception&& exception) { constexpr auto make_exceptional_continuable(error_type exception) {
return make_continuable<FirstArg, Rest...>( // ... return make_continuable<FirstArg, Rest...>( // ...
[exception = std::forward<Exception>(exception)](auto&& promise) { [exception = std::move(exception)](auto&& promise) mutable {
std::forward<decltype(promise)>(promise).set_exception( std::forward<decltype(promise)>(promise).set_exception(
std::move(exception)); std::move(exception));
}); });
} }
/// 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 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 detail::types::error_type;
} // namespace cti } // namespace cti
#endif // CONTINUABLE_BASE_HPP_INCLUDED #endif // CONTINUABLE_BASE_HPP_INCLUDED