Zen C++ Libraries
Zero-dependency re-usable components for C++
Loading...
Searching...
No Matches
include
zen
config.hpp
1
#ifndef ZEN_CONFIG_HPP
2
#define ZEN_CONFIG_HPP
3
4
#include <stdio.h>
5
#include <cstdlib>
6
7
#ifndef ZEN_NAMESPACE
8
#define ZEN_NAMESPACE zen
9
#endif
10
11
#ifndef ZEN_NAMESPACE_START
12
#define ZEN_NAMESPACE_START namespace zen {
13
#endif
14
15
#ifndef ZEN_NAMESPACE_END
16
#define ZEN_NAMESPACE_END }
17
#endif
18
19
#define ZEN_CAT(arg) #arg
20
#define ZEN_CAT2(arg) ZEN_CAT(arg)
21
22
#define ZEN_ASSERT(test) \
23
if (!(test)) { \
24
ZEN_PANIC("The invariant " #test " failed to hold. See the stack trace for more details."); \
25
}
26
27
#if ZEN_ENABLE_DEBUG_ASSERTIONS
28
#define ZEN_DEBUG_ASSERT(test) ZEN_ASSERT(test)
29
#else
30
#define ZEN_DEBUG_ASSERT(test)
31
#endif
32
33
#define ZEN_PANIC(message, ...) \
34
fprintf(stderr, __FILE__ ":" ZEN_CAT2(__LINE__) ": " message "\n" __VA_OPT__(,) __VA_ARGS__); \
35
std::abort();
36
37
#define ZEN_UNREACHABLE \
38
ZEN_PANIC("Code that should have been unreachable was executed. This is a bug.");
39
40
#define ZEN_AUTO_SIZE (-1)
41
42
#if __cplusplus >= 201703L
43
#define ZEN_NODISCARD [[nodiscard]]
44
#else
45
#define ZEN_NODISCARD
46
#endif
47
48
#if __cplusplus >= 201402L
49
#define ZEN_DEPRECATED [[deprecated]]
50
#else
51
#define ZEN_DEPRECATED
52
#endif
53
54
#if __has_builtin(__builtin_expect) || defined(__GNUC__)
55
#define ZEN_LIKELY(expr) __builtin_expect((bool)(expr), true)
56
#define ZEN_UNLIKELY(expr) __builtin_expect((bool)(expr), false)
57
#else
58
#define ZEN_LIKELY(expr) (expr)
59
#define ZEN_UNLIKELY(expr) (expr)
60
#endif
61
62
#define ZEN_NOEXCEPT noexcept
63
64
#endif
// of #ifndef ZEN_CONFIG_HPP
65
Generated by
1.15.0