Please consider the following little function. It provides compiler abstraction for breaking the debugger programmatically:
inline constexpr void BreakDebug()
{
#ifdef __GNUC__
__builtin_trap();
#elif defined _MSC_VER
__debugbreak();
#endif
}
I would like to rewrite the function and replace the preprocessor instructions using C++20 code. Since __builtin_trap
and __debugbreak
are compiler specific and mutual exclusive, I can't use a simple if constexpr
since I would get a compilation error.
Assuming I would wrap the compiler macros __GNUC__
and _MSC_VER
using a constexpr
enumeration constant... how could that be done?