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:
Danny Robson 2018-04-24 15:11:18 +10:00
parent e2b55c7ee5
commit f5399450ab

View File

@ -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, \