debug: add RETURN_UNLESS convenience macro
returns a given value unless a condition is true. primarily useful for computing is_valid and breaking if one of the preconditions isn't valid.
This commit is contained in:
parent
e2b55c7ee5
commit
f5399450ab
15
debug.hpp
15
debug.hpp
@ -93,6 +93,21 @@
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
#define RETURN_UNLESS(VALUE,CONDITION) do { \
|
||||||
|
if (const auto &__return_unless = (CONDITION); !__return_unless) { \
|
||||||
|
if constexpr (debug_enabled) { \
|
||||||
|
std::clog << __FILE__ << ':' \
|
||||||
|
<< __LINE__ << ':' \
|
||||||
|
<< __PRETTY_FUNCTION__ << "; " \
|
||||||
|
<< #CONDITION << '\n'; \
|
||||||
|
breakpoint (); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
return (VALUE); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define _CHECK_PANIC(FMT,...) do { \
|
#define _CHECK_PANIC(FMT,...) do { \
|
||||||
panic ("%s:%s:%i:%s\n" FMT, \
|
panic ("%s:%s:%i:%s\n" FMT, \
|
||||||
|
Loading…
Reference in New Issue
Block a user