From 8c378b44e2fb38b538323630d94f5244e19aa0dd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 9 Mar 2020 16:44:13 +0100 Subject: [PATCH] Add wxDO_IF() helper macro This will be used for wxLogXXX() macros reimplementation in the next commit. --- include/wx/cpp.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/wx/cpp.h b/include/wx/cpp.h index c25c91fe1c..422ab032e9 100644 --- a/include/wx/cpp.h +++ b/include/wx/cpp.h @@ -96,6 +96,27 @@ #define wxSTATEMENT_MACRO_BEGIN do { #define wxSTATEMENT_MACRO_END } while ( (void)0, 0 ) +/* + Helper for executing the following statement conditionally without using + conditional statements. + + This strange macro is needed in the first place to avoid the problems due + to nested if/else inside macros. E.g. if some MACRO started with "if", then + + if ( cond ) + MACRO(); + else + ... + + would be broken because "..." would bind to the wrong "if" inside the macro + rather than the visible one. So we use wxDO_IF() inside the macro instead + to avoid this problem. + */ +#define wxDO_IF_HELPER(loopvar, condition) \ + for ( bool loopvar = false; !loopvar && condition; loopvar = true ) + +#define wxDO_IF(condition) wxDO_IF_HELPER(wxMAKE_UNIQUE_NAME(wxdoif), condition) + /* Define __WXFUNCTION__ which is like standard __FUNCTION__ but defined as NULL for the compilers which don't support the latter.