[ox] Add makeCatch function

This commit is contained in:
Gary Talent 2023-05-30 20:49:57 -05:00
parent 03a1a8abca
commit 90ef5866dd

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;
/**