24 #include <type_traits>
28 #ifndef __STDC_LIMIT_MACROS
29 # define __STDC_LIMIT_MACROS
33 #if defined(__FreeBSD__)
34 # include <sys/param.h>
42 # ifndef WIN32_LEAN_AND_MEAN
43 # define WIN32_LEAN_AND_MEAN
81 #if (__cplusplus >= 202001L)
82 # define OIIO_CPLUSPLUS_VERSION 20
83 # define OIIO_CONSTEXPR17 constexpr
84 # define OIIO_CONSTEXPR20 constexpr
85 # define OIIO_INLINE_CONSTEXPR inline constexpr
86 #elif (__cplusplus >= 201703L)
87 # define OIIO_CPLUSPLUS_VERSION 17
88 # define OIIO_CONSTEXPR17 constexpr
89 # define OIIO_CONSTEXPR20
90 # define OIIO_INLINE_CONSTEXPR inline constexpr
91 #elif (__cplusplus >= 201402L) || (defined(_MSC_VER) && _MSC_VER >= 1914)
92 # define OIIO_CPLUSPLUS_VERSION 14
93 # define OIIO_CONSTEXPR17
94 # define OIIO_CONSTEXPR20
95 # define OIIO_INLINE_CONSTEXPR constexpr
97 # error "This version of OIIO is meant to work only with C++14 and above"
101 #define OIIO_CONSTEXPR14 constexpr
104 #define OIIO_CONSTEXPR constexpr
105 #define OIIO_CONSTEXPR_OR_CONST constexpr
108 #define OIIO_NOEXCEPT noexcept
113 #ifndef __has_cpp_attribute
114 # define __has_cpp_attribute(x) 0
118 #ifndef __has_attribute
119 # define __has_attribute(x) 0
124 #ifndef __has_include
125 # define __has_include(x) 0
145 #if defined(__GNUC__) && !defined(__clang__)
146 # define OIIO_GNUC_VERSION (10000*__GNUC__ + 100*__GNUC_MINOR__ + __GNUC_PATCHLEVEL__)
148 # define OIIO_GNUC_VERSION 0
155 #if defined(__clang__) && !defined(__apple_build_version__) && !defined(__INTEL_LLVM_COMPILER)
156 # define OIIO_CLANG_VERSION (10000*__clang_major__ + 100*__clang_minor__ + __clang_patchlevel__)
158 # define OIIO_CLANG_VERSION 0
163 #if defined(__clang__) && defined(__apple_build_version__)
164 # if defined(__INTEL_LLVM_COMPILER)
165 # error Not expected for __INTEL_LLVM_COMPILER to be defined with an __apple_build_version__
170 # define OIIO_APPLE_CLANG_VERSION (10000*__clang_major__ + 100*__clang_minor__ + __clang_patchlevel__)
172 # define OIIO_APPLE_CLANG_VERSION 0
177 #if defined(__INTEL_COMPILER)
178 # define OIIO_INTEL_COMPILER_VERSION __INTEL_COMPILER
180 # define OIIO_INTEL_COMPILER_VERSION 0
185 #if !defined(__INTEL_COMPILER) && defined(__clang__)
186 # define OIIO_NON_INTEL_CLANG __clang__
188 # define OIIO_NON_INTEL_CLANG 0
196 #if defined(__INTEL_LLVM_COMPILER)
197 # define OIIO_INTEL_LLVM_COMPILER __INTEL_LLVM_COMPILER
198 # define OIIO_INTEL_CLANG_VERSION (10000*__clang_major__ + 100*__clang_minor__ + __clang_patchlevel__)
200 # define OIIO_INTEL_LLVM_COMPILER 0
201 # define OIIO_INTEL_CLANG_VERSION 0
206 #if defined(__clang__)
207 # define OIIO_ANY_CLANG 1
209 # define OIIO_ANY_CLANG 0
213 #if defined(_MSC_VER)
214 # define OIIO_MSVS_AT_LEAST_2013 (_MSC_VER >= 1800)
215 # define OIIO_MSVS_BEFORE_2013 (_MSC_VER < 1800)
216 # define OIIO_MSVS_AT_LEAST_2015 (_MSC_VER >= 1900)
217 # define OIIO_MSVS_BEFORE_2015 (_MSC_VER < 1900)
218 # define OIIO_MSVS_AT_LEAST_2017 (_MSC_VER >= 1910)
219 # define OIIO_MSVS_BEFORE_2017 (_MSC_VER < 1910)
220 # if OIIO_MSVS_BEFORE_2017
221 # error "This version of OIIO is meant to work only with Visual Studio 2017 or later"
224 # define OIIO_MSVS_AT_LEAST_2013 0
225 # define OIIO_MSVS_BEFORE_2013 0
226 # define OIIO_MSVS_AT_LEAST_2015 0
227 # define OIIO_MSVS_BEFORE_2015 0
228 # define OIIO_MSVS_AT_LEAST_2017 0
229 # define OIIO_MSVS_BEFORE_2017 0
245 #if defined(_MSC_VER)
247 #define OIIO_PRAGMA(UnQuotedPragma) __pragma(UnQuotedPragma)
250 #define OIIO_PRAGMA(UnQuotedPragma) _Pragma(#UnQuotedPragma)
253 #if defined(__GNUC__)
254 # define OIIO_PRAGMA_WARNING_PUSH OIIO_PRAGMA(GCC diagnostic push)
255 # define OIIO_PRAGMA_WARNING_POP OIIO_PRAGMA(GCC diagnostic pop)
256 # define OIIO_PRAGMA_VISIBILITY_PUSH OIIO_PRAGMA(GCC visibility push(default))
257 # define OIIO_PRAGMA_VISIBILITY_POP OIIO_PRAGMA(GCC visibility pop)
258 # define OIIO_GCC_PRAGMA(UnQuotedPragma) OIIO_PRAGMA(UnQuotedPragma)
259 # if defined(__clang__)
260 # define OIIO_CLANG_PRAGMA(UnQuotedPragma) OIIO_PRAGMA(UnQuotedPragma)
261 # define OIIO_GCC_ONLY_PRAGMA(UnQuotedPragma)
263 # define OIIO_CLANG_PRAGMA(UnQuotedPragma)
264 # define OIIO_GCC_ONLY_PRAGMA(UnQuotedPragma) OIIO_PRAGMA(UnQuotedPragma)
266 # if defined(__INTEL_COMPILER)
267 # define OIIO_INTEL_PRAGMA(UnQuotedPragma) OIIO_PRAGMA(UnQuotedPragma)
269 # define OIIO_INTEL_PRAGMA(UnQuotedPragma)
271 # if defined(__INTEL_LLVM_COMPILER)
272 # define OIIO_INTEL_LLVM_PRAGMA(UnQuotedPragma) OIIO_PRAGMA(UnQuotedPragma)
274 # define OIIO_INTEL_LLVM_PRAGMA(UnQuotedPragma)
276 # define OIIO_MSVS_PRAGMA(UnQuotedPragma)
277 #elif defined(_MSC_VER)
278 # define OIIO_PRAGMA_WARNING_PUSH __pragma(warning(push))
279 # define OIIO_PRAGMA_WARNING_POP __pragma(warning(pop))
280 # define OIIO_PRAGMA_VISIBILITY_PUSH
281 # define OIIO_PRAGMA_VISIBILITY_POP
282 # define OIIO_GCC_PRAGMA(UnQuotedPragma)
283 # define OIIO_GCC_ONLY_PRAGMA(UnQuotedPragma)
284 # define OIIO_CLANG_PRAGMA(UnQuotedPragma)
285 # define OIIO_INTEL_PRAGMA(UnQuotedPragma)
286 # define OIIO_INTEL_LLVM_PRAGMA(UnQuotedPragma)
287 # define OIIO_MSVS_PRAGMA(UnQuotedPragma) OIIO_PRAGMA(UnQuotedPragma)
289 # define OIIO_PRAGMA_WARNING_PUSH
290 # define OIIO_PRAGMA_WARNING_POP
291 # define OIIO_PRAGMA_VISIBILITY_PUSH
292 # define OIIO_PRAGMA_VISIBILITY_POP
293 # define OIIO_GCC_PRAGMA(UnQuotedPragma)
294 # define OIIO_GCC_ONLY_PRAGMA(UnQuotedPragma)
295 # define OIIO_CLANG_PRAGMA(UnQuotedPragma)
296 # define OIIO_INTEL_PRAGMA(UnQuotedPragma)
297 # define OIIO_INTEL_LLVM_PRAGMA(UnQuotedPragma)
298 # define OIIO_MSVS_PRAGMA(UnQuotedPragma)
315 #if defined(__GNUC__)
316 # define OIIO_ALLOCA(type, size) (assert(size < (1<<20)), (size) != 0 ? ((type*)__builtin_alloca((size) * sizeof(type))) : nullptr)
318 # define OIIO_ALLOCA(type, size) (assert(size < (1<<20)), (size) != 0 ? ((type*)alloca((size) * sizeof(type))) : nullptr)
322 #define ALLOCA(type, size) OIIO_ALLOCA(type, size)
332 #define OIIO_ALLOCATE_STACK_OR_HEAP(var, T, size) \
333 size_t var##___size = size_t(size); \
334 std::unique_ptr<T[]> var##___heap; \
335 if (var##___size * sizeof(T) <= (1 << 16)) { \
336 var = OIIO_ALLOCA(T, var##___size); \
338 var##___heap.reset(new T[var##___size]); \
339 var = var##___heap.get(); \
346 #if defined(__GNUC__) || __has_attribute(aligned)
347 # define OIIO_ALIGN(size) __attribute__((aligned(size)))
348 #elif defined(_MSC_VER)
349 # define OIIO_ALIGN(size) __declspec(align(size))
350 #elif defined(__INTEL_COMPILER)
351 # define OIIO_ALIGN(size) __declspec(align((size)))
353 # define OIIO_ALIGN(size) alignas(size)
358 #define OIIO_CACHE_LINE_SIZE 64
361 #define OIIO_CACHE_ALIGN OIIO_ALIGN(OIIO_CACHE_LINE_SIZE)
375 #if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
376 # define OIIO_LIKELY(x) (__builtin_expect(bool(x), true))
377 # define OIIO_UNLIKELY(x) (__builtin_expect(bool(x), false))
379 # define OIIO_LIKELY(x) (x)
380 # define OIIO_UNLIKELY(x) (x)
388 #if defined(__CUDACC__)
389 # define OIIO_FORCEINLINE __inline__
390 #elif defined(__GNUC__) || defined(__clang__) || __has_attribute(always_inline)
391 # define OIIO_FORCEINLINE inline __attribute__((always_inline))
392 #elif defined(_MSC_VER) || defined(__INTEL_COMPILER)
393 # define OIIO_FORCEINLINE __forceinline
395 # define OIIO_FORCEINLINE inline
404 #if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER) || __has_attribute(pure)
405 # define OIIO_PURE_FUNC __attribute__((pure))
406 #elif defined(_MSC_VER)
407 # define OIIO_PURE_FUNC
409 # define OIIO_PURE_FUNC
418 #if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER) || __has_attribute(const)
419 # define OIIO_CONST_FUNC __attribute__((const))
420 #elif defined(_MSC_VER)
421 # define OIIO_CONST_FUNC
423 # define OIIO_CONST_FUNC
428 #if OIIO_CPLUSPLUS_VERSION >= 17 || __has_cpp_attribute(maybe_unused)
429 # define OIIO_MAYBE_UNUSED [[maybe_unused]]
430 #elif defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER) || __has_attribute(unused)
431 # define OIIO_MAYBE_UNUSED __attribute__((unused))
433 # define OIIO_MAYBE_UNUSED
437 #define OIIO_UNUSED_OK OIIO_MAYBE_UNUSED
442 #if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) || defined(__INTEL_COMPILER)
443 # define OIIO_RESTRICT __restrict
445 # define OIIO_RESTRICT
451 #if OIIO_CPLUSPLUS_VERSION >= 14 || __has_cpp_attribute(deprecated)
452 # define OIIO_DEPRECATED(msg) [[deprecated(msg)]]
453 #elif defined(__GNUC__) || defined(__clang__) || __has_attribute(deprecated)
454 # define OIIO_DEPRECATED(msg) __attribute__((deprecated(msg)))
455 #elif defined(_MSC_VER)
456 # define OIIO_DEPRECATED(msg) __declspec(deprecated(msg))
458 # define OIIO_DEPRECATED(msg)
465 #if OIIO_CPLUSPLUS_VERSION >= 17 || __has_cpp_attribute(fallthrough)
466 # define OIIO_FALLTHROUGH [[fallthrough]]
468 # define OIIO_FALLTHROUGH
474 #if OIIO_CPLUSPLUS_VERSION >= 17 || __has_cpp_attribute(nodiscard)
475 # define OIIO_NODISCARD [[nodiscard]]
477 # define OIIO_NODISCARD
486 #if defined(__clang__) || (defined(__GNUC__) && !defined(__INTEL_COMPILER)) \
487 || __has_attribute(no_sanitize_address)
488 # define OIIO_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
490 # define OIIO_NO_SANITIZE_ADDRESS
497 #if defined(__clang__) || defined(__GNUC__) || __has_attribute(returns_nonnull)
498 # define OIIO_RETURNS_NONNULL __attribute__((returns_nonnull))
500 # define OIIO_RETURNS_NONNULL
507 # define OIIO_HOSTDEVICE __host__ __device__
509 # define OIIO_HOSTDEVICE
516 #if defined(__PRETTY_FUNCTION__)
517 # define OIIO_PRETTY_FUNCTION __PRETTY_FUNCTION__
518 #elif defined(__FUNCSIG__)
519 # define OIIO_PRETTY_FUNCTION __FUNCSIG__
521 # define OIIO_PRETTY_FUNCTION __FUNCTION__
538 little = __ORDER_LITTLE_ENDIAN__,
539 big = __ORDER_BIG_ENDIAN__,
563 inline void cpuid (
int info[4],
int infoType,
int extra)
567 #if (defined(_WIN32) || defined(__i386__) || defined(__x86_64__))
569 __cpuidex(info, infoType, extra);
570 # elif defined(__x86_64__)
571 __asm__ __volatile__ (
573 :
"=a" (info[0]),
"=b" (info[1]),
"=c" (info[2]),
"=d" (info[3])
574 :
"0" (infoType),
"2" (extra));
576 __asm__ __volatile__ (
577 "mov{l}\t{%%}ebx, %1 \n\t"
579 "xchg{l}\t{%%}ebx, %1 \n\t"
580 :
"=a" (info[0]),
"=r" (info[1]),
"=c" (info[2]),
"=d" (info[3])
581 :
"0" (infoType),
"2" (extra));
584 info[0] = 0; info[1] = 0; info[2] = 0; info[3] = 0;
614 template <
typename T,
class... Args>
616 static_assert(
alignof(
T) >
alignof(
void*),
"Type doesn't seem to be over-aligned, aligned_new is not required");
620 return ptr ?
new (
ptr)
T(std::forward<Args>(
args)...) :
nullptr;
624 template <
typename T>
634 #if OIIO_CPLUSPLUS_VERSION >= 14
638 template <
bool B,
class T =
void>
645 #define OIIO_ENABLE_IF(...) OIIO::enable_if_t<(__VA_ARGS__), int> = 0
typename std::enable_if< B, T >::type enable_if_t
Define Imath::enable_if_t to be std for C++14, equivalent for C++11.
**If you just want to fire and args
#define OIIO_NAMESPACE_END
#define OIIO_NAMESPACE_BEGIN