4#if defined(SC_COMPILER_ENABLE_CONFIG)
16#define SC_COMPILER_CLANG 1
17#define SC_COMPILER_GCC 0
18#define SC_COMPILER_MSVC 0
21#define SC_COMPILER_CLANG_CL 1
23#define SC_COMPILER_CLANG_CL 0
27#define SC_COMPILER_CLANG 0
28#define SC_COMPILER_GCC 0
29#define SC_COMPILER_MSVC 1
30#define SC_COMPILER_CLANG_CL 0
33#define SC_COMPILER_CLANG 0
34#define SC_COMPILER_GCC 1
35#define SC_COMPILER_MSVC 0
36#define SC_COMPILER_CLANG_CL 0
41#define SC_COMPILER_FORCE_INLINE __forceinline
42#define SC_COMPILER_DEBUG_BREAK __debugbreak()
46#define SC_COMPILER_FORCE_INLINE __attribute__((always_inline)) inline
47#if defined(__has_builtin)
48#if __has_builtin(__builtin_debugtrap)
49#define SC_COMPILER_DEBUG_BREAK __builtin_debugtrap()
50#elif __has_builtin(__builtin_trap)
51#define SC_COMPILER_DEBUG_BREAK __builtin_trap()
53#error "No __builtin_trap or __builtin_debugtrap"
56#error "No __has_builtin"
64#if defined(SC_PLUGIN_LIBRARY)
65#define SC_COMPILER_EXPORT __declspec(dllimport)
66#define SC_COMPILER_EXTERN extern
68#define SC_COMPILER_EXPORT __declspec(dllexport)
69#define SC_COMPILER_EXTERN
74#define SC_COMPILER_EXTERN
75#if defined(SC_PLUGIN_LIBRARY)
76#define SC_COMPILER_EXPORT
78#define SC_COMPILER_EXPORT \
79 __attribute__((visibility("default")))
84#if !DOXYGEN && defined(SC_LIBRARY_PATH)
85#define SC_COMPILER_MACRO_ESCAPE(input) __SC_COMPILER_MACRO_ESCAPE_HELPER(input)
86#define __SC_COMPILER_MACRO_ESCAPE_HELPER(input) #input
87#define __SC_COMPILER_MACRO_TO_LITERAL(string) #string
88#define SC_COMPILER_MACRO_TO_LITERAL(string) \
89 __SC_COMPILER_MACRO_TO_LITERAL(string)
90#define SC_COMPILER_LIBRARY_PATH \
91 SC_COMPILER_MACRO_TO_LITERAL(SC_COMPILER_MACRO_ESCAPE(SC_LIBRARY_PATH))
95#if defined(__SANITIZE_ADDRESS__)
96#define SC_COMPILER_ASAN 1
98#define SC_COMPILER_ASAN 0
102#if defined(__clang__)
103#define SC_COMPILER_WARNING_POP _Pragma("clang diagnostic pop")
104#elif defined(__GNUC__)
105#define SC_COMPILER_WARNING_POP _Pragma("GCC diagnostic pop")
107#define SC_COMPILER_WARNING_POP _Pragma("warning(pop)")
111#define SC_COMPILER_OFFSETOF(Class, Field) __builtin_offsetof(Class, Field)
115template <
int offset,
typename T,
typename R>
116T& fieldOffset(R&
object)
118 return *
reinterpret_cast<T*
>(
reinterpret_cast<char*
>(&object) - offset);
122#define SC_COMPILER_FIELD_OFFSET(Class, Field, Value) \
123 SC::fieldOffset<SC_COMPILER_OFFSETOF(Class, Field), Class, decltype(Class::Field)>(Value);
127#define SC_COMPILER_WARNING_PUSH_OFFSETOF \
128 _Pragma("clang diagnostic push"); \
129 _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"");
131#define SC_COMPILER_WARNING_PUSH_OFFSETOF \
132 _Pragma("GCC diagnostic push"); \
133 _Pragma("GCC diagnostic ignored \"-Winvalid-offsetof\"");
135#define SC_COMPILER_WARNING_PUSH_OFFSETOF _Pragma("warning(push)")
139#define SC_COMPILER_UNUSED(param) ((void)param)
143#define SC_COMPILER_WARNING_PUSH_UNUSED_RESULT \
144 _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wunused-result\"")
146#define SC_COMPILER_WARNING_PUSH_UNUSED_RESULT \
147 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wunused-result\"")
149#define SC_COMPILER_WARNING_PUSH_UNUSED_RESULT _Pragma("warning(push)") _Pragma("warning(disable : 4834 6031)")
154#if defined(SC_LANGUAGE_FORCE_STANDARD_CPP)
155#if SC_LANGUAGE_FORCE_STANDARD_CPP == 14
156#define SC_LANGUAGE_CPP_VERSION 201402L
157#elif SC_LANGUAGE_FORCE_STANDARD_CPP == 17
158#define SC_LANGUAGE_CPP_VERSION 201703L
159#elif SC_LANGUAGE_FORCE_STANDARD_CPP == 20
160#define SC_LANGUAGE_CPP_VERSION 202002L
162#error "SC_LANGUAGE_FORCE_STANDARD_CPP has invalid value"
168#define SC_LANGUAGE_CPP_VERSION _MSVC_LANG
170#define SC_LANGUAGE_CPP_VERSION __cplusplus
175#if SC_LANGUAGE_CPP_VERSION >= 202002L
176#define SC_LANGUAGE_CPP_LESS_THAN_20 0
177#define SC_LANGUAGE_CPP_AT_LEAST_20 1
178#define SC_LANGUAGE_CPP_AT_LEAST_17 1
179#define SC_LANGUAGE_CPP_AT_LEAST_14 1
181#elif SC_LANGUAGE_CPP_VERSION >= 201703L
183#define SC_LANGUAGE_CPP_LESS_THAN_20 1
184#define SC_LANGUAGE_CPP_AT_LEAST_20 0
185#define SC_LANGUAGE_CPP_AT_LEAST_17 1
186#define SC_LANGUAGE_CPP_AT_LEAST_14 1
188#elif SC_LANGUAGE_CPP_VERSION >= 201402L
190#define SC_LANGUAGE_CPP_LESS_THAN_20 1
191#define SC_LANGUAGE_CPP_AT_LEAST_20 0
192#define SC_LANGUAGE_CPP_AT_LEAST_17 0
193#define SC_LANGUAGE_CPP_AT_LEAST_14 1
197#define SC_LANGUAGE_CPP_LESS_THAN_20 1
198#define SC_LANGUAGE_CPP_AT_LEAST_20 0
199#define SC_LANGUAGE_CPP_AT_LEAST_17 0
200#define SC_LANGUAGE_CPP_AT_LEAST_14 0
204#undef SC_LANGUAGE_CPP_VERSION
206#if SC_LANGUAGE_CPP_AT_LEAST_20
207#define SC_LANGUAGE_LIKELY [[likely]]
208#define SC_LANGUAGE_UNLIKELY [[unlikely]]
210#define SC_LANGUAGE_LIKELY
211#define SC_LANGUAGE_UNLIKELY
214#if SC_LANGUAGE_CPP_AT_LEAST_17
215#define SC_LANGUAGE_IF_CONSTEXPR constexpr
217#define SC_LANGUAGE_IF_CONSTEXPR
220#if __cpp_exceptions == 199711 || _EXCEPTIONS
221#define SC_LANGUAGE_EXCEPTIONS 1
223#define SC_LANGUAGE_EXCEPTIONS 0
226#ifndef __has_cpp_attribute
227#define SC_LANGUAGE_LIFETIME_BOUND
228#elif __has_cpp_attribute(msvc::lifetimebound)
229#define SC_LANGUAGE_LIFETIME_BOUND [[msvc::lifetimebound]]
230#elif __has_cpp_attribute(clang::lifetimebound)
231#define SC_LANGUAGE_LIFETIME_BOUND [[clang::lifetimebound]]
232#elif __has_cpp_attribute(lifetimebound)
233#define SC_LANGUAGE_LIFETIME_BOUND [[lifetimebound]]
235#define SC_LANGUAGE_LIFETIME_BOUND
250template <
class T>
struct RemoveReference<T&&> {
using type = T; };
253template <
class T>
struct IsLValueReference<T&> {
static constexpr bool value =
true; };
256template <
class T>
struct IsRValueReference<T&&>{
static constexpr bool value =
true; };
269template <
typename T>
constexpr T&&
move(T& value) {
return static_cast<T&&
>(value); }
272template <
typename T>
constexpr T&&
forward(
typename TypeTraits::RemoveReference<T>::type& value) {
return static_cast<T&&
>(value); }
275template <
typename T>
constexpr T&&
forward(
typename TypeTraits::RemoveReference<T>::type&& value)
278 return static_cast<T&&
>(value);
282template <
typename T>
constexpr inline void swap(T& t1, T& t2)
300template <
typename T>
constexpr const T&
min(
const T& t1,
const T& t2) {
return t1 < t2 ? t1 : t2; }
302template <
typename T>
constexpr const T&
max(
const T& t1,
const T& t2) {
return t1 > t2 ? t1 : t2; }
constexpr const T & min(const T &t1, const T &t2)
Finds the minimum of two values.
Definition: Compiler.h:300
constexpr const T & max(const T &t1, const T &t2)
Finds the maximum of two values.
Definition: Compiler.h:302
constexpr T && move(T &value)
Converts an lvalue to an rvalue reference.
Definition: Compiler.h:269
constexpr void swap(T &t1, T &t2)
Swaps the values of two objects.
Definition: Compiler.h:282
constexpr T && forward(typename TypeTraits::RemoveReference< T >::type &&value)
Forwards an rvalue as an rvalue reference, with a check that it's not an lvalue reference.
Definition: Compiler.h:275
Determines if a type is an lvalue reference.
Definition: Compiler.h:252
Determines if a type is an rvalue reference.
Definition: Compiler.h:255
Removes reference from a type T.
Definition: Compiler.h:248