Engine
Raylib based game framework
Loading...
Searching...
No Matches
Assert.h
1#pragma once
2
3#include <cstdarg>
4#include <cstdio>
5#include <cstdlib>
6#include <iostream>
7
8#define ASSERT
9
10#ifdef ASSERT
11
12template <typename... Args>
13inline void AssertFail(const char* expr, const char* file, int line, const char* func, Args&&... args)
14{
15 std::fprintf(stderr, "[ASSERTION FAILED]\n");
16 std::fprintf(stderr, " Expression: %s\n", expr);
17 std::fprintf(stderr, " Location: %s:%d (%s)\n", file, line, func);
18
19 if constexpr (sizeof...(args) > 0)
20 {
21 std::cerr << " Message: ";
22 (std::cerr << ... << std::forward<Args>(args));
23 std::cerr << '\n';
24 }
25
26 std::fflush(stderr);
27 std::abort();
28}
29
30#define Assert(expr, ...) \
31 ((expr) ? static_cast<void>(0) : AssertFail(#expr, __FILE__, __LINE__, __func__ __VA_OPT__(, ) __VA_ARGS__))
32
33#else
34
35#define Assert(expr, ...) ((void)0)
36
37#endif