From b7fec28cf7cd0d2876f32030cfd9ce11e0bb2b69 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Fri, 13 Sep 2019 00:40:28 +0200 Subject: [PATCH] crimson: abstract the error type in unthrowable_wrapper. Signed-off-by: Radoslaw Zarzynski --- src/crimson/common/errorator.h | 38 +++++++++++++++------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/crimson/common/errorator.h b/src/crimson/common/errorator.h index 4fa1e22d402..30ef2d02d7c 100644 --- a/src/crimson/common/errorator.h +++ b/src/crimson/common/errorator.h @@ -21,9 +21,9 @@ namespace _impl { // would like to `throw make_error<...>)()` instead of returning. // returning allows for the compile-time verification of future's // AllowedErrorsV and also avoid the burden of throwing. -template <_impl::ct_error ErrorV> +template struct unthrowable_wrapper { - using wrapped_type = decltype(ErrorV); + using is_error = std::true_type; unthrowable_wrapper(const unthrowable_wrapper&) = delete; static constexpr unthrowable_wrapper instance{}; @@ -102,6 +102,16 @@ public: template struct errorator { + template > + struct is_error : std::false_type {}; + template + struct is_error> : T::is_error {}; + template + static inline constexpr bool is_error_v = is_error::value; + + static_assert((... && is_error_v), + "errorator expects presence of ::is_error in all error types"); + template class future : private seastar::future { using base_t = seastar::future; @@ -112,20 +122,6 @@ struct errorator { template friend class maybe_handle_error_t; - template > - struct is_error { - static constexpr bool value = false; - }; - template - struct is_error> { - // specialization for _impl::ct_error. it could be written in much - // simpler form – without void_t and is_same_v. - static constexpr bool value = \ - std::is_same_v; - }; - template - static inline constexpr bool is_error_v = is_error::value; - template > struct get_errorator { // generic template for non-errorated things (plain types and @@ -414,11 +410,11 @@ public: }; // class errorator, <> specialization namespace ct_error { - using enoent = unthrowable_wrapper<_impl::ct_error::enoent>; - using enodata = unthrowable_wrapper<_impl::ct_error::enodata>; - using invarg = unthrowable_wrapper<_impl::ct_error::invarg>; - using input_output_error = unthrowable_wrapper<_impl::ct_error::input_output_error>; - using object_corrupted = unthrowable_wrapper<_impl::ct_error::object_corrupted>; + using enoent = unthrowable_wrapper<_impl::ct_error, _impl::ct_error::enoent>; + using enodata = unthrowable_wrapper<_impl::ct_error, _impl::ct_error::enodata>; + using invarg = unthrowable_wrapper<_impl::ct_error, _impl::ct_error::invarg>; + using input_output_error = unthrowable_wrapper<_impl::ct_error, _impl::ct_error::input_output_error>; + using object_corrupted = unthrowable_wrapper<_impl::ct_error, _impl::ct_error::object_corrupted>; } } // namespace crimson