Is there any secret trick that I've overlooked, maybe in C++11/14, that would allow me to call DebugBreak() (a void function) while in the top scope of the if-statement?
If DebugBreak() would return anything, I guess it would've been "trivial".
Background
In my pursuit of writing a specialized Assert-function, I'm stuck. Currently, code looks like this:
if ( MyClass* instance = GetLastObject() )
I want to add a CHK() macro that developers can drop in:
if ( MyClass* instance = CHK( GetLastObject() ) )
If the condition within CHK() is false, an assert will be displayed. With some Lambda magic I'm able to call DebugBreak() inside the CHK macro and it works fine, except that the execution is halted inside the Lambda; forcing developers to move one step down the callstack if hit.
If I could force the compiler to inline the lambda, that could work as well, but I haven't found any way of doing that either.
Edit: A simplified version of the CHK(f) macro, sorry for formatting:
[&]() {auto CHK_test = (f); if (CHK_test) return CHK_test; else { __debugbreak(); return (decltype(CHK_test))0; } } ( )