From f5399450ab5ab7e4f509cd55a8dfdc3e82de3a27 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 24 Apr 2018 15:11:18 +1000 Subject: [PATCH] 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. --- debug.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/debug.hpp b/debug.hpp index 77b1e2c1..564ac93b 100644 --- a/debug.hpp +++ b/debug.hpp @@ -93,6 +93,21 @@ } 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 { \ panic ("%s:%s:%i:%s\n" FMT, \