DSC Engine
Loading...
Searching...
No Matches
assert.hpp
1#pragma once
2
3
4//https://stackoverflow.com/questions/11761703/overloading-macro-on-number-of-arguments
5#define _nds_assert_1(expr) DSC::__assert__((expr), (#expr))
6#define _nds_assert_2(expr, msg) DSC::__assert__((expr), (msg))
7
8#define _ARG2(_0, _1, _2, ...) _2
9#define NARG2(...) _ARG2(__VA_ARGS__, 2, 1, 0)
10
11#define __nds_assert_N(N, ...) _nds_assert_ ## N (__VA_ARGS__)
12#define _nds_assert_N(N, ...) __nds_assert_N(N, __VA_ARGS__)
13
14// calling it nds_assert to differentiate it from stdlib's assert
15#define nds_assert(...) _nds_assert_N(NARG2(__VA_ARGS__), __VA_ARGS__)
16
17// usage :
18// nds_assert(condition == ?);
19// nds_assert(condition == ?, "Fatal message if failed");
20
21
22namespace DSC
23{
24 void __assert__(bool condition, const char* message);
25}