3#include <sections/Misc.h>
46 :
message(
"NO REASON PROVIDED") {}
71 template<
typename Err_Ty = DefaultError>
91 template<
typename... Args>
92 requires std::is_constructible_v<Err_Ty, Args...>
94 :
error(std::forward<Args>(args)...)
122 template<
typename Res_Ty,
typename Err_Ty = DefaultError>
123 requires (!std::same_as<Res_Ty, void>) && (!std::same_as<Err_Ty, void>)
133 : m_Result(_result), m_FunctionFailed(false)
142 : m_Result(std::move(_result)), m_FunctionFailed(false)
152 : m_Error(std::move(_error.error)), m_FunctionFailed(true)
161 if (m_FunctionFailed)
183 template<Result force = Result::Check>
187 if constexpr (force == Result::Check)
190 if (!m_FunctionFailed)
211 template<Result force = Result::Check>
215 if constexpr (force == Result::Check)
218 if (m_FunctionFailed)
229 inline bool Failed()
const {
return m_FunctionFailed; }
234 inline bool Success()
const {
return !m_FunctionFailed; }
254 const bool m_FunctionFailed;
Class to return a result from a function that can fail.
Definition ReturnVal.h:125
bool Success() const
Returns whether the function suceeded or not.
Definition ReturnVal.h:234
ReturnVal(Res_Ty _result)
Copies the success result.
Definition ReturnVal.h:132
ReturnVal(Res_Ty &&_result)
Moves the success value.
Definition ReturnVal.h:141
bool Failed() const
Returns whether the function failed or not.
Definition ReturnVal.h:229
ReturnVal(FunctionFail< Err_Ty > &&_error)
Moves the contents of a Util::FunctionFail<Err_Ty> to a Util::ReturnVal.
Definition ReturnVal.h:151
Res_Ty & Result()
Returns a const reference to the result.
Definition ReturnVal.h:212
Err_Ty & Error()
Returns a const reference to the error.
Definition ReturnVal.h:184
void EndProcess(bool breakpoint=true)
Ends the current process.
Default error class for Uti::ReturnVal.
Definition ReturnVal.h:41
const char * message
A pointer to a c-string error message, not owned by the class/object.
Definition ReturnVal.h:60
DefaultError(const char *_message)
Provide an error message for the error to carry.
Definition ReturnVal.h:54
DefaultError()
Default constructor, sets the message to "NO REASON PROVIDED".
Definition ReturnVal.h:45
Class to create when a function fails.
Definition ReturnVal.h:73
Err_Ty error
The error that the function is returning.
Definition ReturnVal.h:100
FunctionFail(Err_Ty _error)
Constructor that copies an error and stores it.
Definition ReturnVal.h:77
FunctionFail(Args &&... args)
Constructor that creates the error within the class.
Definition ReturnVal.h:93