IRC_SERVER
By @hyunjunk (hyunjun2372@gmail.com)
Loading...
Searching...
No Matches
MacroDefines.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cassert>
4#include <iostream>
5
6#if !defined(__GNUC__) && !defined(_MSC_VER)
7 #error "This compiler is not supported"
8#endif
9
10/**
11 * Implemented as direct interrupt to avoid dirtying the call stack with assert function when debugging.
12 * And for optimization, change to Assume() in release builds.
13 */
14#if defined(__GNUC__)
15 #if defined(NDEBUG)
16 #define Assert(exp) do { if (!(exp)) __builtin_unreachable(); } while (0)
17 #else
18 #define Assert(exp) do { if (!(exp)) { std::cerr << "Assertion failed: " << #exp << " at " << __FILE__ << ":" << __LINE__ << std::endl; __builtin_trap(); } } while (0)
19 #endif
20#elif defined(_MSC_VER)
21 #if defined(NDEBUG)
22 #define Assert(exp) do { if (!(exp)) __assume(0); } while (0)
23 #else
24 #define Assert(exp) do { if (!(exp)) { std::cerr << "Assertion failed: " << #exp << " at " << __FILE__ << ":" << __LINE__ << std::endl; __debugbreak(); } } while (0)
25 #endif
26#else
27 #if defined(NDEBUG)
28 #define Assert(exp) assert(exp)
29 #else
30 #define Assert(exp) do { if (!(exp)) { std::cerr << "Assertion failed: " << #exp << " at " << __FILE__ << ":" << __LINE__ << std::endl; assert(exp); } } while (0)
31 #endif
32#endif
33
34#if defined(__GNUC__)
35 #define Assume(x) do { if (!(x)) __builtin_unreachable(); } while (0)
36#elif defined(_MSC_VER)
37 #define Assume(x) __assume(x)
38#else
39 #define Assume(x)
40#endif
41
42#define STATIC_ASSERT(exp) UNUSED typedef char static_assertion_[(exp) ? 1 : -1]