debug: expose NDEBUG as a constexpr bool

This commit is contained in:
Danny Robson 2017-09-13 12:37:53 +10:00
parent c1aa0f7a3d
commit d0e49fb1a8

View File

@ -24,13 +24,22 @@
///////////////////////////////////////////////////////////////////////////////
// it is fractionally easier to define a constexpr variable which can be used
// in constexpr-if to enable/disable some codepaths rather than deal with
// macros in some scenarios. eg, templates are complicated enough without
// (more) macros.
#if !defined(NDEBUG)
#define DEBUG_ONLY(X) do { X } while (0)
constexpr bool debug_enabled = true;
#else
#define DEBUG_ONLY(X) do { } while (0)
constexpr bool debug_enabled = false;
#endif
///----------------------------------------------------------------------------
/// enable some code only if assertions et al are enabled
#define DEBUG_ONLY(X) do { if constexpr (debug_enabled) { X } } while (0)
///////////////////////////////////////////////////////////////////////////////
#define EXIT_XSUCCESS 0
#define EXIT_XSKIP 77