]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common/crimson/errorator: add universal pass_further_all, discard_all, all_same_way
authorSamuel Just <sjust@redhat.com>
Fri, 17 Jan 2020 20:56:46 +0000 (12:56 -0800)
committerSamuel Just <sjust@redhat.com>
Sat, 15 Feb 2020 01:28:38 +0000 (17:28 -0800)
In many cases, we simply want to add catch-all handling.

Signed-off-by: Samuel Just <sjust@redhat.com>
src/crimson/common/errorator.h

index d9ae99913df4fff3f743c5d80a8602183059d02a..3750b67360a50a004524752dd2cc51d0e93c1986 100644 (file)
@@ -872,6 +872,31 @@ namespace ct_error {
     ct_error_code<std::errc::operation_not_supported>;
   using not_connected = ct_error_code<std::errc::not_connected>;
   using timed_out = ct_error_code<std::errc::timed_out>;
+
+  struct pass_further_all {
+    template <class ErrorT>
+    decltype(auto) operator()(ErrorT&& e) {
+      return std::forward<ErrorT>(e);
+    }
+  };
+
+  struct discard_all {
+    template <class ErrorT>
+    decltype(auto) operator()(ErrorT&&) {
+    }
+  };
+
+  template <class ErrorFunc>
+  static decltype(auto) all_same_way(ErrorFunc&& error_func) {
+    return [
+      error_func = std::forward<ErrorFunc>(error_func)
+    ] (auto&& e) mutable -> decltype(auto) {
+      using decayed_t = std::decay_t<decltype(e)>;
+      auto&& handler =
+        decayed_t::error_t::handle(std::forward<ErrorFunc>(error_func));
+      return std::invoke(std::move(handler), std::forward<decltype(e)>(e));
+    };
+  };
 }
 
 using stateful_errc = stateful_error_t<std::errc>;