From 3a3968b26889cd25bf673072a3814c1e6895a031 Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 30 Dec 2022 18:46:27 +0100 Subject: [PATCH] Result: Add nonnull_or_error() --- luna/include/luna/Result.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/luna/include/luna/Result.h b/luna/include/luna/Result.h index 36124bac..df34375b 100644 --- a/luna/include/luna/Result.h +++ b/luna/include/luna/Result.h @@ -202,3 +202,10 @@ template <> class Result if (!_expr_rc.has_value()) return _expr_rc.release_error(); \ _expr_rc.release_value(); \ }) + +template inline Result nonnull_or_error(T* ptr, int error) +{ + if (ptr == nullptr) return err(error); + else + return ptr; +} \ No newline at end of file