Skip to content

Instantly share code, notes, and snippets.

@jfalcou
Last active January 7, 2020 22:13
Show Gist options
  • Save jfalcou/472885 to your computer and use it in GitHub Desktop.
Save jfalcou/472885 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <type_traits>
#if defined(__unix__)
#include <signal.h>
#include <unistd.h>
#endif
#if (defined(_M_IX86) || defined(__i386__) || defined(_M_IA64) || defined(__ia64__)) && defined(__GNUC__)
#define DEBUG_TRAP() __asm("int3")
#elif defined(_MSC_VER)
#define DEBUG_TRAP() __debugbreak()
#elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
#define DEBUG_TRAP() kill(getpid(), SIGTRAP)
#else
#error I dont know how to SIGTRAP on this platform
#endif
template<bool Condition>
std::enable_if_t<Condition> trap()
{
DEBUG_TRAP();
}
template<bool Condition> std::enable_if_t<!Condition> trap() {}
template<int N> void foo()
{
trap< (N<4) >();
std::cout << N << std::endl;
}
int main()
{
foo<7>();
foo<1>();
foo<3>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment