3 #ifndef __has_cpp_attribute
4 # define __has_cpp_attribute(x) 0
6 #ifndef __has_extension
7 # define __has_extension(x) 0
10 # define __has_feature(x) 0
13 # define __has_include(x) 0
16 # define __has_builtin(x) 0
19 #define PLUGIFY_HAS_EXCEPTIONS (__cpp_exceptions || __EXCEPTIONS || _HAS_EXCEPTIONS)
21 #ifndef PLUGIFY_EXCEPTIONS
22 # if PLUGIFY_HAS_EXCEPTIONS
23 # define PLUGIFY_EXCEPTIONS 1
25 # define PLUGIFY_EXCEPTIONS 0
29 #if PLUGIFY_EXCEPTIONS && (!PLUGIFY_HAS_EXCEPTIONS || !__has_include(<stdexcept>))
30 # undef PLUGIFY_EXCEPTIONS
31 # define PLUGIFY_EXCEPTIONS 0
34 #ifndef PLUGIFY_FALLBACK_ASSERT
35 # define PLUGIFY_FALLBACK_ASSERT 1
38 #if PLUGIFY_FALLBACK_ASSERT && !__has_include(<cassert>)
39 # undef PLUGIFY_FALLBACK_ASSERT
40 # define PLUGIFY_FALLBACK_ASSERT 0
43 #ifndef PLUGIFY_FALLBACK_ABORT
44 # define PLUGIFY_FALLBACK_ABORT 1
47 #if PLUGIFY_FALLBACK_ABORT && !__has_include(<cstdlib>)
48 # undef PLUGIFY_FALLBACK_ABORT
49 # define PLUGIFY_FALLBACK_ABORT 0
52 #ifndef PLUGIFY_FALLBACK_ABORT_FUNCTION
53 # define PLUGIFY_FALLBACK_ABORT_FUNCTION [] (auto) { }
56 #if PLUGIFY_EXCEPTIONS
58 # define PLUGIFY_ASSERT(x, str, e) do { if (!(x)) [[unlikely]] throw e(str); } while (0)
59 #elif PLUGIFY_FALLBACK_ASSERT
61 # define PLUGIFY_ASSERT(x, str, ...) assert(x && str)
62 #elif PLUGIFY_FALLBACK_ABORT
64 # define PLUGIFY_ASSERT(x, ...) do { if (!(x)) [[unlikely]] { std::abort(); } } while (0)
66 # define PLUGIFY_ASSERT(x, str, ...) do { if (!(x)) [[unlikely]] { PLUGIFY_FALLBACK_ABORT_FUNCTION (str); { while (true) { [] { } (); } } } } while (0)
69 #define PLUGIFY_PRAGMA_IMPL(x) _Pragma(#x)
70 #define PLUGIFY_PRAGMA(x) PLUGIFY_PRAGMA_IMPL(x)
72 #if defined(__clang__)
73 # define PLUGIFY_PRAGMA_DIAG_PREFIX clang
74 #elif defined(__GNUC__)
75 # define PLUGIFY_PRAGMA_DIAG_PREFIX GCC
78 #if defined(__GNUC__) || defined(__clang__)
79 # define PLUGIFY_WARN_PUSH() PLUGIFY_PRAGMA(PLUGIFY_PRAGMA_DIAG_PREFIX diagnostic push)
80 # define PLUGIFY_WARN_IGNORE(wrn) PLUGIFY_PRAGMA(PLUGIFY_PRAGMA_DIAG_PREFIX diagnostic ignored wrn)
81 # define PLUGIFY_WARN_POP() PLUGIFY_PRAGMA(PLUGIFY_PRAGMA_DIAG_PREFIX diagnostic pop)
82 #elif defined(_MSC_VER)
83 # define PLUGIFY_WARN_PUSH() __pragma(warning(push))
84 # define PLUGIFY_WARN_IGNORE(wrn) __pragma(warning(disable: wrn))
85 # define PLUGIFY_WARN_POP() __pragma(warning(pop))
88 #if defined(__GNUC__) || defined(__clang__)
89 # define PLUGIFY_PACK(decl) decl __attribute__((__packed__))
90 #elif defined(_MSC_VER)
91 # define PLUGIFY_PACK(decl) __pragma(pack(push, 1)) decl __pragma(pack(pop))
93 # define PLUGIFY_PACK(decl) decl
96 #if defined(__GNUC__) || defined(__clang__)
97 # define PLUGIFY_UNREACHABLE() __builtin_unreachable()
98 #elif defined (_MSC_VER)
99 # define PLUGIFY_UNREACHABLE() __assume(false)
101 # error "Compiler not supported, please report an issue."
104 #if defined(_MSC_VER)
105 # define PLUGIFY_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
107 # define PLUGIFY_NO_UNIQUE_ADDRESS [[no_unique_address]]
110 #if defined(__clang__)
111 # define PLUGIFY_FORCE_INLINE [[gnu::always_inline]] [[gnu::gnu_inline]] extern inline
112 #elif defined(__GNUC__)
113 # define PLUGIFY_FORCE_INLINE [[gnu::always_inline]] inline
114 #elif defined(_MSC_VER)
115 # pragma warning(error: 4714)
116 # define PLUGIFY_FORCE_INLINE __forceinline
118 # define PLUGIFY_FORCE_INLINE inline
121 #if defined(__GNUC__) || defined(__clang__)
122 # define PLUGIFY_RESTRICT __restrict__
123 #elif defined(_MSC_VER)
124 # define PLUGIFY_RESTRICT __restrict
126 # define PLUGIFY_RESTRICT