70 #ifdef VLINK_LIBRARY_STATIC
72 #elif defined(_WIN32) || defined(__CYGWIN__)
75 #define VLINK_EXPORT __declspec(dllexport)
77 #define VLINK_EXPORT __declspec(dllimport)
81 #define VLINK_EXPORT __attribute__((visibility("default")))
85 #undef VLINK_EXPORT_AND_ALIGNED
87 #define VLINK_EXPORT_AND_ALIGNED(align_num) VLINK_EXPORT __declspec(align(align_num))
99 #define VLINK_EXPORT_AND_ALIGNED(align_num) VLINK_EXPORT __attribute__((aligned(align_num)))
103 #if defined(_WIN32) && !defined(WIN32_LEAN_AND_MEAN)
104 #define WIN32_LEAN_AND_MEAN
109 #ifndef _CRT_SECURE_NO_WARNINGS
110 #define _CRT_SECURE_NO_WARNINGS
112 #pragma warning(disable : 4065)
113 #pragma warning(disable : 4251)
114 #pragma warning(disable : 4244)
115 #pragma warning(disable : 4267)
116 #pragma warning(disable : 4324)
117 #pragma warning(disable : 4702)
118 #pragma warning(disable : 4819)
119 #pragma warning(disable : 4840)
120 #pragma warning(disable : 4996)
124 #ifndef __has_builtin
125 #define __has_builtin(x) 0
129 #if __cplusplus >= 202002L
140 #define VLINK_LIKELY(x) (x) [[likely]]
150 #define VLINK_UNLIKELY(x) (x) [[unlikely]]
153 #define VLINK_LIKELY(x) (x)
154 #define VLINK_UNLIKELY(x) (x)
156 #define VLINK_LIKELY(x) (__builtin_expect(!!(x), 1))
157 #define VLINK_UNLIKELY(x) (__builtin_expect(!!(x), 0))
161 #define VLINK_LIKELY(x) (x)
162 #define VLINK_UNLIKELY(x) (x)
174 #define VLINK_DISALLOW_COPY_AND_ASSIGN(classname) \
175 classname(const classname&) = delete; \
176 classname& operator=(const classname&) = delete;
192 #define VLINK_SINGLETON_CHECK(classname) \
194 struct ConstructorChecker { \
195 inline ConstructorChecker() { \
196 static_assert(std::is_final_v<classname>, "Constructor must be final."); \
197 static_assert(!std::is_default_constructible_v<classname>, "Constructor must be private."); \
199 static std::atomic_flag flag; \
201 if VLINK_UNLIKELY (flag.test_and_set(std::memory_order_seq_cst)) { \
202 throw std::runtime_error("Constructor has been instantiated."); \
207 ConstructorChecker constructor_checker_;
232 #define VLINK_SINGLETON_DECLARE(classname) \
234 inline static classname& get() { \
235 static classname singleton = classname(); \
240 VLINK_SINGLETON_CHECK(classname) \
241 VLINK_DISALLOW_COPY_AND_ASSIGN(classname)
249 #define VLINK_MACRO_STRING_IFY(name) #name
261 #define VLINK_MACRO_STRING_GET(name) VLINK_MACRO_STRING_IFY(name)
263 #if __has_builtin(__builtin_constant_p)
274 #define VLINK_ASSERT_CONSTANT(msg) static_assert(__builtin_constant_p(msg), "Must be a constant string literal.");
276 #define VLINK_ASSERT_CONSTANT(msg)
279 #if !defined(VLIKELY) && !defined(VUNLIKELY)
284 #define VLIKELY(...) VLINK_LIKELY(__VA_ARGS__)
289 #define VUNLIKELY(...) VLINK_UNLIKELY(__VA_ARGS__)