feat: add cubed_assert lib

This commit is contained in:
2026-03-06 22:07:42 +08:00
parent 05a62e7443
commit d51c68ddb4

View File

@@ -0,0 +1,35 @@
#pragma once
#include <Cubed/tools/log.hpp>
namespace Assert {
inline void msg(const char* condition, const char* file,
int line, const char* func,
const std::string& message
) {
LOG::error("Assertion failed: {} at {}: {} in function {}",
condition, file, line, func);
if (!message.empty()) {
LOG::error("Message: {}", message);
}
std::abort();
}
}
#ifdef NDEBUG
#define CUBED_ASSERT(cond) ((void)0)
#define CUBED_ASSERT_MSG(cond) ((void)0)
#else
#define CUBED_ASSERT(cond) \
do { \
if (!(cond)) { \
::Assert::msg(#cond, __FILE__, __LINE__, __func__); \
} \
} while (0)
#define CUBED_ASSERT_MSG(cond, message) \
do { \
if (!(cond)) { \
::Assert::msg(#cond, __FILE__, __LINE__, __func__, message); \
} \
} while (0)
#endif