]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/common: extend errorator with assert_all{}.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Thu, 21 May 2020 21:13:21 +0000 (23:13 +0200)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Mon, 25 May 2020 12:28:34 +0000 (14:28 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/crimson/common/errorator.h

index b7a7c8eff0031e480582119bb1d7c9894e0e9c89..ea68e351ec2cb1966eb8141f8d83a035a0b97c8e 100644 (file)
@@ -8,6 +8,8 @@
 
 #include <seastar/core/future-util.hh>
 
+#include "include/ceph_assert.h"
+
 namespace crimson {
 
 template<typename Iterator, typename AsyncAction>
@@ -728,6 +730,28 @@ public:
     }
   };
 
+  // assert_all{ "TODO" };
+  class assert_all {
+    const char* const msg = nullptr;
+  public:
+    template <std::size_t N>
+    assert_all(const char (&msg)[N])
+      : msg(msg) {
+    }
+    assert_all() = default;
+
+    template <class ErrorT, EnableIf<ErrorT>...>
+    void operator()(ErrorT&&) {
+      static_assert(contains_once_v<std::decay_t<ErrorT>>,
+                    "discarding disallowed ErrorT");
+      if (msg) {
+        ceph_abort(msg);
+      } else {
+        ceph_abort();
+      }
+    }
+  };
+
   template <class ErrorFunc>
   static decltype(auto) all_same_way(ErrorFunc&& error_func) {
     return all_same_way_t<ErrorFunc>{std::forward<ErrorFunc>(error_func)};
@@ -951,6 +975,25 @@ namespace ct_error {
     }
   };
 
+  class assert_all {
+    const char* const msg = nullptr;
+  public:
+    template <std::size_t N>
+    assert_all(const char (&msg)[N])
+      : msg(msg) {
+    }
+    assert_all() = default;
+
+    template <class ErrorT>
+    void operator()(ErrorT&&) {
+      if (msg) {
+        ceph_abort(msg);
+      } else {
+        ceph_abort();
+      }
+    }
+  };
+
   template <class ErrorFunc>
   static decltype(auto) all_same_way(ErrorFunc&& error_func) {
     return [