Go to the documentation of this file.
3 #ifndef COPP_UTILS_FEATURES_H
4 #define COPP_UTILS_FEATURES_H
9 #include <libcopp/utils/config/libcopp_build_features.h>
13 #if defined(__GCCXML__)
14 # define COPP_MACRO_COMPILER_GCCXML 1
15 #elif defined(__clang__)
16 # define COPP_MACRO_COMPILER_CLANG 1
17 #elif defined(_MSC_VER)
18 # define COPP_MACRO_COMPILER_MSVC 1
19 #elif defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || defined(__ECC)
20 # define COPP_MACRO_COMPILER_INTELC 1
21 #elif defined(__GNUC__)
22 # define COPP_MACRO_COMPILER_GCC 1
23 #elif defined(__BORLANDC__)
24 # define COPP_MACRO_COMPILER_BORLANDC 1
29 #if (defined(linux) || defined(__linux) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)) && \
31 # define COPP_MACRO_PLATFORM_LINUX
32 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
33 # define COPP_MACRO_PLATFORM_BSD
34 #elif defined(sun) || defined(__sun)
35 # define COPP_MACRO_PLATFORM_SOLARIS
37 # define COPP_MACRO_PLATFORM_SGI
39 # define COPP_MACRO_PLATFORM_HPUNIX
40 #elif defined(__CYGWIN__)
41 # define COPP_MACRO_PLATFORM_CYGWIN
42 #elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
43 # define COPP_MACRO_PLATFORM_WIN32
45 # if defined(unix) || defined(__unix) || defined(_XOPEN_SOURCE) || defined(_POSIX_SOURCE)
46 # define COPP_MACRO_PLATFORM_UNIX
54 #if defined(COPP_MACRO_COMPILER_MSVC)
55 # define COPP_HAS_ABI_HEADERS 1
56 # define COPP_ABI_PREFIX "libcopp/utils/abi/msvc_prefix.hpp"
57 # define COPP_ABI_SUFFIX "libcopp/utils/abi/msvc_suffix.hpp"
58 #elif defined COPP_MACRO_COMPILER_BORLANDC
59 # define COPP_HAS_ABI_HEADERS 1
60 # define COPP_ABI_PREFIX "libcopp/utils/abi/borland_prefix.hpp"
61 # define COPP_ABI_SUFFIX "libcopp/utils/abi/borland_suffix.hpp"
67 #if defined(LIBCOPP_MACRO_USE_SEGMENTED_STACKS)
68 # if !((defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ > 3 && __GNUC_MINOR__ > 6))) || \
69 (defined(__clang__) && __clang_major__ > 2 && __clang_minor__ > 3))
70 # error "compiler does not support segmented_stack stacks"
72 # define COPP_MACRO_SEGMENTED_STACK_NUMBER 10
75 #ifndef COPP_MACRO_CPP_STD
76 # if defined(__cplusplus) && __cplusplus >= 201103L
77 # define COPP_MACRO_CPP_STD 201103L
78 # define COPP_MACRO_ENABLE_SMART_PTR 1
80 # define COPP_MACRO_CPP_STD 199711L
84 #if defined(_POSIX_MT_) || defined(_MSC_VER)
85 # define COPP_MACRO_ENABLE_MULTI_THREAD
90 #if !defined(COPP_LIKELY_IF) && defined(__cplusplus)
92 # if defined(__has_cpp_attribute) && (defined(__clang__) || !defined(__GNUC__) || __GNUC__ > 9)
93 # if __has_cpp_attribute(likely)
94 # define COPP_LIKELY_IF(...) if (__VA_ARGS__) [[likely]]
98 #if !defined(COPP_LIKELY_IF) && (defined(__clang__) || defined(__GNUC__))
99 # define COPP_LIKELY_IF(...) if (__builtin_expect(!!(__VA_ARGS__), true))
101 #ifndef COPP_LIKELY_IF
102 # define COPP_LIKELY_IF(...) if (__VA_ARGS__)
105 #if !defined(COPP_UNLIKELY_IF) && defined(__cplusplus)
107 # if defined(__has_cpp_attribute) && (defined(__clang__) || !defined(__GNUC__) || __GNUC__ > 9)
108 # if __has_cpp_attribute(likely)
109 # define COPP_UNLIKELY_IF(...) if (__VA_ARGS__) [[unlikely]]
113 #if !defined(COPP_UNLIKELY_IF) && (defined(__clang__) || defined(__GNUC__))
114 # define COPP_UNLIKELY_IF(...) if (__builtin_expect(!!(__VA_ARGS__), false))
116 #ifndef COPP_UNLIKELY_IF
117 # define COPP_UNLIKELY_IF(...) if (__VA_ARGS__)
122 #if !defined(COPP_NORETURN_ATTR) && defined(__has_cpp_attribute)
123 # if __has_cpp_attribute(noreturn)
124 # define COPP_NORETURN_ATTR [[noreturn]]
127 #ifndef COPP_NORETURN_ATTR
128 # define COPP_NORETURN_ATTR
131 #ifndef COPP_UNREACHABLE
132 # if defined(__cpp_lib_unreachable)
133 # if __cpp_lib_unreachable
134 # define COPP_UNREACHABLE() std::unreachable()
137 # if !defined(COPP_UNREACHABLE) && defined(unreachable)
138 # define COPP_UNREACHABLE() unreachable()
140 # if !defined(COPP_UNREACHABLE)
143 # if __has_builtin(__builtin_unreachable)
144 # define COPP_UNREACHABLE() __builtin_unreachable()
147 # if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
148 # define COPP_UNREACHABLE() __builtin_unreachable()
154 #if !defined(COPP_UNREACHABLE)
155 # if defined(_DEBUG) || !defined(NDEBUG)
156 # define COPP_UNREACHABLE() std::abort()
158 # define COPP_UNREACHABLE()
164 #if !defined(COPP_MACRO_RV_REF)
165 # define COPP_MACRO_RV_REF &&
168 #if !defined(COPP_MACRO_STD_MOVE)
169 # define COPP_MACRO_STD_MOVE(x) std::move(x)
172 #if !defined(COPP_MACRO_STD_FORWARD)
173 # define COPP_MACRO_STD_FORWARD(t, x) std::forward<t>(x)
177 #if defined(COPP_MACRO_COMPILER_GCC)
178 # if (__GNUC__ * 100 + __GNUC_MINOR__) >= 408 && __cplusplus >= 201103L
179 # define COPP_MACRO_COMPILER_CXX_THREAD_LOCAL 1
181 # define COPP_MACRO_COMPILER_CXX_THREAD_LOCAL 0
183 #elif defined(COPP_MACRO_COMPILER_CLANG)
184 # if __has_feature(cxx_thread_local)
185 # define COPP_MACRO_COMPILER_CXX_THREAD_LOCAL 1
187 # define COPP_MACRO_COMPILER_CXX_THREAD_LOCAL 0
189 #elif defined(_MSC_VER)
190 # if _MSC_VER >= 1900
191 # define COPP_MACRO_COMPILER_CXX_THREAD_LOCAL 1
193 # define COPP_MACRO_COMPILER_CXX_THREAD_LOCAL 0
198 #if defined(__APPLE__)
199 # include <TargetConditionals.h>
201 # if TARGET_OS_IPHONE || TARGET_OS_EMBEDDED || TARGET_IPHONE_SIMULATOR
202 # define COPP_MACRO_DISABLE_THREAD_LOCAL_KEYWORK
207 #if defined(__ANDROID__)
208 # define COPP_MACRO_DISABLE_THREAD_LOCAL_KEYWORK
211 #if !defined(COPP_MACRO_DISABLE_THREAD_LOCAL_KEYWORK)
212 # if defined(COPP_MACRO_COMPILER_CXX_THREAD_LOCAL) && COPP_MACRO_COMPILER_CXX_THREAD_LOCAL
213 # define COPP_MACRO_THREAD_LOCAL thread_local
214 # elif defined(COPP_MACRO_COMPILER_GCC) || defined(COPP_MACRO_COMPILER_CLANG)
215 # define COPP_MACRO_THREAD_LOCAL __thread
216 # elif defined(_MSC_VER)
217 # define COPP_MACRO_THREAD_LOCAL __declspec(thread)