From 89feb434552745387ebd59ef7a6eb40cee4c3255 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Thu, 21 May 2020 23:13:21 +0200 Subject: [PATCH] crimson/common: extend errorator with assert_all{}. Signed-off-by: Radoslaw Zarzynski --- src/crimson/common/errorator.h | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/crimson/common/errorator.h b/src/crimson/common/errorator.h index b7a7c8eff00..ea68e351ec2 100644 --- a/src/crimson/common/errorator.h +++ b/src/crimson/common/errorator.h @@ -8,6 +8,8 @@ #include +#include "include/ceph_assert.h" + namespace crimson { template @@ -728,6 +730,28 @@ public: } }; + // assert_all{ "TODO" }; + class assert_all { + const char* const msg = nullptr; + public: + template + assert_all(const char (&msg)[N]) + : msg(msg) { + } + assert_all() = default; + + template ...> + void operator()(ErrorT&&) { + static_assert(contains_once_v>, + "discarding disallowed ErrorT"); + if (msg) { + ceph_abort(msg); + } else { + ceph_abort(); + } + } + }; + template static decltype(auto) all_same_way(ErrorFunc&& error_func) { return all_same_way_t{std::forward(error_func)}; @@ -951,6 +975,25 @@ namespace ct_error { } }; + class assert_all { + const char* const msg = nullptr; + public: + template + assert_all(const char (&msg)[N]) + : msg(msg) { + } + assert_all() = default; + + template + void operator()(ErrorT&&) { + if (msg) { + ceph_abort(msg); + } else { + ceph_abort(); + } + } + }; + template static decltype(auto) all_same_way(ErrorFunc&& error_func) { return [ -- 2.39.5