Result: Add nonnull_or_error()

This commit is contained in:
apio 2022-12-30 18:46:27 +01:00
parent 973e39a255
commit 3a3968b268
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -202,3 +202,10 @@ template <> class Result<void>
if (!_expr_rc.has_value()) return _expr_rc.release_error(); \
_expr_rc.release_value(); \
})
template <typename T> inline Result<T*> nonnull_or_error(T* ptr, int error)
{
if (ptr == nullptr) return err(error);
else
return ptr;
}