diff --git a/dCommon/GeneralUtils.h b/dCommon/GeneralUtils.h index 69534b58..30be70be 100644 --- a/dCommon/GeneralUtils.h +++ b/dCommon/GeneralUtils.h @@ -243,6 +243,12 @@ namespace GeneralUtils { return std::nullopt; } + // A version of TryParse that will return `errorVal` if `str` failed to parse. + template + [[nodiscard]] T TryParse(std::string_view str, const T errorVal) { + return TryParse(str).value_or(errorVal); + } + #endif /**