[ox] Add makeCatch function

(synced from 90ef5866dd)
This commit is contained in:
2023-05-30 20:49:57 -05:00
parent 6513d9a2a0
commit e6ea8b581e
+16
View File
@@ -50,6 +50,22 @@ constexpr T *make(Args &&...args) noexcept {
#endif
}
template<typename T, typename ...Args>
[[nodiscard]]
constexpr Result<T*> makeCatch(Args &&...args) noexcept {
#ifdef __cpp_exceptions
try {
return new T(ox::forward<Args>(args)...);
} catch (const ox::Exception &ex) {
return ex.toError();
} catch (...) {
return OxError(1, "Allocation or constructor failed");
}
#else
return new T(ox::forward<Args>(args)...);
#endif
}
constexpr auto MallocaStackLimit = defines::UseStdLib ? 1024 : 0;
/**