Cleaned up Util functions

This commit is contained in:
Pasha Bibko
2025-07-20 21:04:24 +01:00
parent cc0300b66c
commit 6a0d2fc0a2
3 changed files with 107 additions and 103 deletions

View File

@@ -24,10 +24,10 @@ namespace LXC::Util
}
// Custom version of std::unexpected //
template<typename ErrorType> struct FunctionFail
template<typename ErrorType> struct FunctionFail final
{
explicit FunctionFail(ErrorType _err)
: error(_err)
// Basic constructor to copy the error across //
explicit FunctionFail(ErrorType _err) : error(_err)
{
// Only checks for a debugger when compiled in Debug mode //
#ifdef _DEBUG
@@ -39,13 +39,28 @@ namespace LXC::Util
#endif // _DEBUG
}
ErrorType error;
// Constructs the FunctionFail with the error itself //
template<typename... Args> requires std::constructible_from<ErrorType, Args...>
explicit FunctionFail(Args&&... args)
: error(std::forward<Args>(args)...)
{
// Only checks for a debugger when compiled in Debug mode //
#ifdef _DEBUG
// Triggers a breakpoint when a debugger is attached as a function has failed //
if (IsDebuggerPresent())
DebugBreak();
#endif // _DEBUG
}
const ErrorType error;
};
// Custom version of std::expected //
template<typename ResultType, typename ErrorType>
requires (!std::same_as<ResultType, bool>) // ResultType being bool causes issues with operator overloads
class ReturnVal
class ReturnVal final
{
public:
// Constructor for function sucess //