Changed to use concepts instead of static_assert

This commit is contained in:
Pasha Bibko
2025-05-07 19:43:09 +01:00
parent 98fc4589ab
commit c472cb5fc5
11 changed files with 65 additions and 47 deletions

View File

@@ -5,16 +5,11 @@ namespace LX
// Util function to throw an error if the condition is met //
// Given error type must derive from LX::RuntimeError //
template<typename Error, typename... Args>
template<typename Error, typename... Args> requires
std::is_constructible_v<Error, Args...> && // <- Checks the arguments can be used to construct the object
std::is_base_of_v<LX::RuntimeError, Error> // <- Checks the error class is a child of LX::RuntimeError
inline void ThrowIf(const bool condition, Args&&... args)
{
// Checks that the error type will be caught by the error checker //
static_assert
(
std::is_base_of_v<LX::RuntimeError, Error>,
"Must throw a type that derives from LX::RuntimeError"
);
// Checks if the condition is met and micro-optimises that errors will not be thrown //
if (condition) [[unlikely]]
{