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