Calling void functions inside a condition - statement inside an if

Is there any secret trick I missed, maybe in C ++ 11/14, that would allow me to call DebugBreak()

(a void function) while at the top of an if-statement?

If it DebugBreak()

returns anything, I think it would be "trivial".

Background

In my quest to write a specialized Assert function, I am stuck. Currently, the code looks like this:

if ( MyClass* instance = GetLastObject() )

      

I want to add a CHK () macro that developers can add:

if ( MyClass* instance = CHK( GetLastObject() ) )

      

If the condition inside CHK()

is false, the statement will be displayed. With some Lambda magic I can call DebugBreak()

inside a macro CHK

, and it works fine, except that execution is stopped inside Lambda; forcing developers to move one step down the stop cost if hit.

If I could get the compiler to inline the lambda, that might work too, but I haven't found any way to do it either.

Edit: simplified version of the macro CHK(f)

, sorry for the formatting:

[&]() {auto CHK_test = (f); if (CHK_test) return CHK_test; else { __debugbreak(); return (decltype(CHK_test))0; } } ( )

      

+3


source to share





All Articles