quill
Attributes.h
1 
7 #pragma once
8 
9 #ifndef QUILL_BEGIN_NAMESPACE
10  #define QUILL_BEGIN_NAMESPACE \
11  namespace quill \
12  { \
13  inline namespace v11 \
14  {
15  #define QUILL_END_NAMESPACE \
16  } \
17  }
18 #endif
19 
20 #ifdef _MSVC_LANG
21  #define QUILL_CPLUSPLUS _MSVC_LANG
22 #else
23  #define QUILL_CPLUSPLUS __cplusplus
24 #endif
25 
29 #ifndef QUILL_HAS_INCLUDE
30  #ifdef __has_include
31  #define QUILL_HAS_INCLUDE(x) __has_include(x)
32  #else
33  #define QUILL_HAS_INCLUDE(x) 0
34  #endif
35 #endif
36 
40 #ifndef QUILL_HAS_FEATURE
41  #ifdef __has_feature
42  #define QUILL_HAS_FEATURE(x) __has_feature(x)
43  #else
44  #define QUILL_HAS_FEATURE(x) 0
45  #endif
46 #endif
47 
51 #ifndef QUILL_HAS_ATTRIBUTE
52  #ifdef __has_attribute
53  #define QUILL_HAS_ATTRIBUTE(x) __has_attribute(x)
54  #else
55  #define QUILL_HAS_ATTRIBUTE(x) 0
56  #endif
57 #endif
58 
62 #ifndef QUILL_HAS_CPP_ATTRIBUTE
63  #if defined(__cplusplus) && defined(__has_cpp_attribute)
64  #define QUILL_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
65  #else
66  #define QUILL_HAS_CPP_ATTRIBUTE(x) 0
67  #endif
68 #endif
69 
73 #ifndef QUILL_NODISCARD
74  #if QUILL_HAS_CPP_ATTRIBUTE(nodiscard)
75  #define QUILL_NODISCARD [[nodiscard]]
76  #elif QUILL_HAS_CPP_ATTRIBUTE(gnu::warn_unused_result)
77  #define QUILL_NODISCARD [[gnu::warn_unused_result]]
78  #else
79  #define QUILL_NODISCARD
80  #endif
81 #endif
82 
86 #ifndef QUILL_MAYBE_UNUSED
87  #if QUILL_HAS_CPP_ATTRIBUTE(maybe_unused) && (__cplusplus >= 201703L)
88  #define QUILL_MAYBE_UNUSED [[maybe_unused]]
89  #elif QUILL_HAS_ATTRIBUTE(__unused__)
90  #define QUILL_MAYBE_UNUSED __attribute__((__unused__))
91  #elif defined(_MSC_VER)
92  #define QUILL_MAYBE_UNUSED __pragma(warning(suppress : 4100))
93  #else
94  #define QUILL_MAYBE_UNUSED
95  #endif
96 #endif
97 
104 #ifndef QUILL_ATTRIBUTE_HOT
105  #if QUILL_HAS_ATTRIBUTE(hot)
106  #define QUILL_ATTRIBUTE_HOT __attribute__((hot))
107  #else
108  #define QUILL_ATTRIBUTE_HOT
109  #endif
110 #endif
111 
112 #ifndef QUILL_ATTRIBUTE_COLD
113  #if QUILL_HAS_ATTRIBUTE(cold)
114  #define QUILL_ATTRIBUTE_COLD __attribute__((cold))
115  #else
116  #define QUILL_ATTRIBUTE_COLD
117  #endif
118 #endif
119 
123 #ifndef QUILL_ATTRIBUTE_USED
124  #if QUILL_HAS_ATTRIBUTE(used)
125  #define QUILL_ATTRIBUTE_USED __attribute__((used))
126  #else
127  #define QUILL_ATTRIBUTE_USED
128  #endif
129 #endif
130 
134 #ifndef QUILL_LIKELY
135  #if defined(__GNUC__)
136  #define QUILL_LIKELY(x) (__builtin_expect((x), 1))
137  #else
138  #define QUILL_LIKELY(x) (x)
139  #endif
140 #endif
141 
142 #ifndef QUILL_UNLIKELY
143  #if defined(__GNUC__)
144  #define QUILL_UNLIKELY(x) (__builtin_expect((x), 0))
145  #else
146  #define QUILL_UNLIKELY(x) (x)
147  #endif
148 #endif
149 
153 #ifndef QUILL_EXPORT
154  #if defined(_WIN32) && defined(_MSC_VER)
155  #if defined(QUILL_DLL_EXPORT)
156  #define QUILL_EXPORT __declspec(dllexport) // Exporting symbols when building the library
157  #elif defined(QUILL_DLL_IMPORT)
158  #define QUILL_EXPORT __declspec(dllimport) // Importing symbols when using the library
159  #else
160  #define QUILL_EXPORT // No special attribute needed for static or other builds
161  #endif
162  #elif defined(__GNUC__) || defined(__clang__)
163  #define QUILL_EXPORT \
164  __attribute__((visibility("default"))) // Using GCC/Clang visibility attribute
165  #else
166  #define QUILL_EXPORT // Default for other compilers
167  #endif
168 #endif
169 
173 #ifndef QUILL_USE_RTTI
174  // __RTTI is for EDG compilers. _CPPRTTI is for MSVC.
175  #if defined(__GXX_RTTI) || QUILL_HAS_FEATURE(cxx_rtti) || defined(_CPPRTTI) || \
176  defined(__INTEL_RTTI__) || defined(__RTTI)
177  #define QUILL_USE_RTTI 1
178  #else
179  #define QUILL_USE_RTTI 0
180  #endif
181 #endif