Cleaned up Util functions
This commit is contained in:
@@ -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 //
|
||||
|
||||
Reference in New Issue
Block a user