Blender V5.0
BLI_utildefines.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5/* Use a define instead of `#pragma once` because of `BLI_memory_utils.h` */
6#ifndef __BLI_UTILDEFINES_H__
7#define __BLI_UTILDEFINES_H__
8
12
13/* avoid many includes for now */
14#include "BLI_compiler_compat.h"
15#include "BLI_sys_types.h"
16#include "BLI_utildefines_variadic.h" // IWYU prama: export
17
18/* We could remove in future. */
19#include "BLI_assert.h"
20
21/* include after _VA_NARGS macro */
23
24#ifdef __cplusplus
25# include <type_traits>
26# include <utility>
27
28extern "C" {
29#endif
30
31/* -------------------------------------------------------------------- */
34
35#ifndef __cplusplus
36# define MIN2(a, b) ((a) < (b) ? (a) : (b))
37# define MAX2(a, b) ((a) > (b) ? (a) : (b))
38#endif
39
40#define INIT_MINMAX(min, max) \
41 { \
42 (min)[0] = (min)[1] = (min)[2] = 1.0e30f; \
43 (max)[0] = (max)[1] = (max)[2] = -1.0e30f; \
44 } \
45 (void)0
46#define INIT_MINMAX2(min, max) \
47 { \
48 (min)[0] = (min)[1] = 1.0e30f; \
49 (max)[0] = (max)[1] = -1.0e30f; \
50 } \
51 (void)0
52
54
55/* -------------------------------------------------------------------- */
58
59#define SWAP(type, a, b) \
60 { \
61 type sw_ap; \
62 CHECK_TYPE(a, type); \
63 CHECK_TYPE(b, type); \
64 sw_ap = (a); \
65 (a) = (b); \
66 (b) = sw_ap; \
67 } \
68 (void)0
69
70/* shift around elements */
71#define SHIFT3(type, a, b, c) \
72 { \
73 type tmp; \
74 CHECK_TYPE(a, type); \
75 CHECK_TYPE(b, type); \
76 CHECK_TYPE(c, type); \
77 tmp = a; \
78 a = c; \
79 c = b; \
80 b = tmp; \
81 } \
82 (void)0
83
84#define SHIFT4(type, a, b, c, d) \
85 { \
86 type tmp; \
87 CHECK_TYPE(a, type); \
88 CHECK_TYPE(b, type); \
89 CHECK_TYPE(c, type); \
90 CHECK_TYPE(d, type); \
91 tmp = a; \
92 a = d; \
93 d = c; \
94 c = b; \
95 b = tmp; \
96 } \
97 (void)0
98
100
101/* -------------------------------------------------------------------- */
104
105/* Manual line breaks for readability. */
106/* clang-format off */
107
108/* ELEM#(v, ...): is the first arg equal any others? */
109/* internal helpers. */
110#define _VA_ELEM2(v, a) ((v) == (a))
111#define _VA_ELEM3(v, a, b) \
112 (_VA_ELEM2(v, a) || _VA_ELEM2(v, b))
113#define _VA_ELEM4(v, a, b, c) \
114 (_VA_ELEM3(v, a, b) || _VA_ELEM2(v, c))
115#define _VA_ELEM5(v, a, b, c, d) \
116 (_VA_ELEM4(v, a, b, c) || _VA_ELEM2(v, d))
117#define _VA_ELEM6(v, a, b, c, d, e) \
118 (_VA_ELEM5(v, a, b, c, d) || _VA_ELEM2(v, e))
119#define _VA_ELEM7(v, a, b, c, d, e, f) \
120 (_VA_ELEM6(v, a, b, c, d, e) || _VA_ELEM2(v, f))
121#define _VA_ELEM8(v, a, b, c, d, e, f, g) \
122 (_VA_ELEM7(v, a, b, c, d, e, f) || _VA_ELEM2(v, g))
123#define _VA_ELEM9(v, a, b, c, d, e, f, g, h) \
124 (_VA_ELEM8(v, a, b, c, d, e, f, g) || _VA_ELEM2(v, h))
125#define _VA_ELEM10(v, a, b, c, d, e, f, g, h, i) \
126 (_VA_ELEM9(v, a, b, c, d, e, f, g, h) || _VA_ELEM2(v, i))
127#define _VA_ELEM11(v, a, b, c, d, e, f, g, h, i, j) \
128 (_VA_ELEM10(v, a, b, c, d, e, f, g, h, i) || _VA_ELEM2(v, j))
129#define _VA_ELEM12(v, a, b, c, d, e, f, g, h, i, j, k) \
130 (_VA_ELEM11(v, a, b, c, d, e, f, g, h, i, j) || _VA_ELEM2(v, k))
131#define _VA_ELEM13(v, a, b, c, d, e, f, g, h, i, j, k, l) \
132 (_VA_ELEM12(v, a, b, c, d, e, f, g, h, i, j, k) || _VA_ELEM2(v, l))
133#define _VA_ELEM14(v, a, b, c, d, e, f, g, h, i, j, k, l, m) \
134 (_VA_ELEM13(v, a, b, c, d, e, f, g, h, i, j, k, l) || _VA_ELEM2(v, m))
135#define _VA_ELEM15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
136 (_VA_ELEM14(v, a, b, c, d, e, f, g, h, i, j, k, l, m) || _VA_ELEM2(v, n))
137#define _VA_ELEM16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \
138 (_VA_ELEM15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n) || _VA_ELEM2(v, o))
139#define _VA_ELEM17(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
140 (_VA_ELEM16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) || _VA_ELEM2(v, p))
141/* clang-format on */
142
143/* reusable ELEM macro */
144#define ELEM(...) VA_NARGS_CALL_OVERLOAD(_VA_ELEM, __VA_ARGS__)
145
147
148/* -------------------------------------------------------------------- */
151
152/* Float equality checks. */
153
154#define IS_EQ(a, b) \
155 (CHECK_TYPE_INLINE_NONCONST(a, double), \
156 CHECK_TYPE_INLINE_NONCONST(b, double), \
157 ((fabs((double)((a) - (b))) >= (double)FLT_EPSILON) ? false : true))
158
159#define IS_EQF(a, b) \
160 (CHECK_TYPE_INLINE_NONCONST(a, float), \
161 CHECK_TYPE_INLINE_NONCONST(b, float), \
162 ((fabsf((float)((a) - (b))) >= (float)FLT_EPSILON) ? false : true))
163
164#define IS_EQT(a, b, c) (((a) > (b)) ? ((((a) - (b)) <= (c))) : (((((b) - (a)) <= (c)))))
165#define IN_RANGE(a, b, c) (((b) < (c)) ? (((b) < (a) && (a) < (c))) : (((c) < (a) && (a) < (b))))
166#define IN_RANGE_INCL(a, b, c) \
167 (((b) < (c)) ? (((b) <= (a) && (a) <= (c))) : (((c) <= (a) && (a) <= (b))))
168
177#define DECIMAL_DIGITS_BOUND(t) (241 * sizeof(t) / 100 + 1)
178
179#ifdef __cplusplus
180inline constexpr int64_t is_power_of_2(const int64_t x)
181{
182 BLI_assert(x >= 0);
183 return (x & (x - 1)) == 0;
184}
185
186inline constexpr int64_t log2_floor(const int64_t x)
187{
188 BLI_assert(x >= 0);
189 return x <= 1 ? 0 : 1 + log2_floor(x >> 1);
190}
191
192inline constexpr int64_t log2_ceil(const int64_t x)
193{
194 BLI_assert(x >= 0);
195 return (is_power_of_2(int(x))) ? log2_floor(x) : log2_floor(x) + 1;
196}
197
198inline constexpr int64_t power_of_2_max(const int64_t x)
199{
200 BLI_assert(x >= 0);
201 return 1ll << log2_ceil(x);
202}
203#endif
204
206
207/* -------------------------------------------------------------------- */
210
211#define CLAMP(a, b, c) \
212 { \
213 if ((a) < (b)) { \
214 (a) = (b); \
215 } \
216 else if ((a) > (c)) { \
217 (a) = (c); \
218 } \
219 } \
220 (void)0
221
222#define CLAMP_MAX(a, c) \
223 { \
224 if ((a) > (c)) { \
225 (a) = (c); \
226 } \
227 } \
228 (void)0
229
230#define CLAMP_MIN(a, b) \
231 { \
232 if ((a) < (b)) { \
233 (a) = (b); \
234 } \
235 } \
236 (void)0
237
239
240/* -------------------------------------------------------------------- */
243
244/* unpack vector for args */
245#define UNPACK2(a) ((a)[0]), ((a)[1])
246#define UNPACK3(a) UNPACK2(a), ((a)[2])
247#define UNPACK4(a) UNPACK3(a), ((a)[3])
248/* pre may be '&', '*' or func, post may be '->member' */
249#define UNPACK2_EX(pre, a, post) (pre((a)[0]) post), (pre((a)[1]) post)
250#define UNPACK3_EX(pre, a, post) UNPACK2_EX(pre, a, post), (pre((a)[2]) post)
251#define UNPACK4_EX(pre, a, post) UNPACK3_EX(pre, a, post), (pre((a)[3]) post)
252
254
255/* -------------------------------------------------------------------- */
258
259#define ARRAY_HAS_ITEM(arr_item, arr_start, arr_len) \
260 (CHECK_TYPE_PAIR_INLINE(arr_start, arr_item), \
261 ((size_t)((arr_item) - (arr_start)) < (size_t)(arr_len)))
262
263/* assuming a static array */
264#ifndef __cplusplus
265# if defined(__GNUC__) && !defined(__cplusplus) && !defined(__clang__) && \
266 !defined(__INTEL_COMPILER)
267# define ARRAY_SIZE(arr) \
268 ((sizeof(struct { int isnt_array : ((const void *)&(arr) == &(arr)[0]); }) * 0) + \
269 (sizeof(arr) / sizeof(*(arr))))
270# else
271# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*(arr)))
272# endif
273#endif
274
275/* ARRAY_SET_ITEMS#(v, ...): set indices of array 'v' */
276/* internal helpers */
277#define _VA_ARRAY_SET_ITEMS2(v, a) ((v)[0] = (a))
278#define _VA_ARRAY_SET_ITEMS3(v, a, b) \
279 _VA_ARRAY_SET_ITEMS2(v, a); \
280 ((v)[1] = (b))
281#define _VA_ARRAY_SET_ITEMS4(v, a, b, c) \
282 _VA_ARRAY_SET_ITEMS3(v, a, b); \
283 ((v)[2] = (c))
284#define _VA_ARRAY_SET_ITEMS5(v, a, b, c, d) \
285 _VA_ARRAY_SET_ITEMS4(v, a, b, c); \
286 ((v)[3] = (d))
287#define _VA_ARRAY_SET_ITEMS6(v, a, b, c, d, e) \
288 _VA_ARRAY_SET_ITEMS5(v, a, b, c, d); \
289 ((v)[4] = (e))
290#define _VA_ARRAY_SET_ITEMS7(v, a, b, c, d, e, f) \
291 _VA_ARRAY_SET_ITEMS6(v, a, b, c, d, e); \
292 ((v)[5] = (f))
293#define _VA_ARRAY_SET_ITEMS8(v, a, b, c, d, e, f, g) \
294 _VA_ARRAY_SET_ITEMS7(v, a, b, c, d, e, f); \
295 ((v)[6] = (g))
296#define _VA_ARRAY_SET_ITEMS9(v, a, b, c, d, e, f, g, h) \
297 _VA_ARRAY_SET_ITEMS8(v, a, b, c, d, e, f, g); \
298 ((v)[7] = (h))
299#define _VA_ARRAY_SET_ITEMS10(v, a, b, c, d, e, f, g, h, i) \
300 _VA_ARRAY_SET_ITEMS9(v, a, b, c, d, e, f, g, h); \
301 ((v)[8] = (i))
302#define _VA_ARRAY_SET_ITEMS11(v, a, b, c, d, e, f, g, h, i, j) \
303 _VA_ARRAY_SET_ITEMS10(v, a, b, c, d, e, f, g, h, i); \
304 ((v)[9] = (j))
305#define _VA_ARRAY_SET_ITEMS12(v, a, b, c, d, e, f, g, h, i, j, k) \
306 _VA_ARRAY_SET_ITEMS11(v, a, b, c, d, e, f, g, h, i, j); \
307 ((v)[10] = (k))
308#define _VA_ARRAY_SET_ITEMS13(v, a, b, c, d, e, f, g, h, i, j, k, l) \
309 _VA_ARRAY_SET_ITEMS12(v, a, b, c, d, e, f, g, h, i, j, k); \
310 ((v)[11] = (l))
311#define _VA_ARRAY_SET_ITEMS14(v, a, b, c, d, e, f, g, h, i, j, k, l, m) \
312 _VA_ARRAY_SET_ITEMS13(v, a, b, c, d, e, f, g, h, i, j, k, l); \
313 ((v)[12] = (m))
314#define _VA_ARRAY_SET_ITEMS15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
315 _VA_ARRAY_SET_ITEMS14(v, a, b, c, d, e, f, g, h, i, j, k, l, m); \
316 ((v)[13] = (n))
317#define _VA_ARRAY_SET_ITEMS16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \
318 _VA_ARRAY_SET_ITEMS15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n); \
319 ((v)[14] = (o))
320#define _VA_ARRAY_SET_ITEMS17(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
321 _VA_ARRAY_SET_ITEMS16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o); \
322 ((v)[15] = (p))
323
324/* reusable ARRAY_SET_ITEMS macro */
325#define ARRAY_SET_ITEMS(...) \
326 { \
327 VA_NARGS_CALL_OVERLOAD(_VA_ARRAY_SET_ITEMS, __VA_ARGS__); \
328 } \
329 (void)0
330
332
333/* -------------------------------------------------------------------- */
336
337#define POINTER_OFFSET(v, ofs) \
338 (reinterpret_cast<typename std::remove_reference<decltype(v)>::type>((char *)(v) + (ofs)))
339
340/* Warning-free macros for storing ints in pointers. Use these _only_
341 * for storing an int in a pointer, not a pointer in an int (64bit)! */
342#define POINTER_FROM_INT(i) ((void *)(intptr_t)(i))
343#define POINTER_AS_INT(i) ((void)0, ((int)(intptr_t)(i)))
344
345#define POINTER_FROM_UINT(i) ((void *)(uintptr_t)(i))
346#define POINTER_AS_UINT(i) ((void)0, ((unsigned int)(uintptr_t)(i)))
347
349
350/* -------------------------------------------------------------------- */
357
359#define OFFSETOF_STRUCT_AFTER(_struct, _member) \
360 ((size_t)(((const char *)&((_struct)->_member)) - ((const char *)(_struct))) + \
361 sizeof((_struct)->_member))
362
368#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member) \
369 { \
370 CHECK_TYPE_NONCONST(struct_dst); \
371 ((void)(struct_dst == struct_src), \
372 memcpy((char *)(struct_dst) + OFFSETOF_STRUCT_AFTER(struct_dst, member), \
373 (const char *)(struct_src) + OFFSETOF_STRUCT_AFTER(struct_dst, member), \
374 sizeof(*(struct_dst)) - OFFSETOF_STRUCT_AFTER(struct_dst, member))); \
375 } \
376 ((void)0)
377
378#define MEMSET_STRUCT_AFTER(struct_var, value, member) \
379 { \
380 CHECK_TYPE_NONCONST(struct_var); \
381 memset((char *)(struct_var) + OFFSETOF_STRUCT_AFTER(struct_var, member), \
382 value, \
383 sizeof(*(struct_var)) - OFFSETOF_STRUCT_AFTER(struct_var, member)); \
384 } \
385 ((void)0)
386
387/* defined
388 * in memory_utils.c for now. I do not know where we should put it actually... */
389#ifndef __BLI_MEMORY_UTILS_H__
393extern bool BLI_memory_is_zero(const void *arr, size_t arr_size);
394#endif
395
396#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member) \
397 (BLI_memory_is_zero((const char *)(struct_var) + OFFSETOF_STRUCT_AFTER(struct_var, member), \
398 sizeof(*(struct_var)) - OFFSETOF_STRUCT_AFTER(struct_var, member)))
399
401
402/* -------------------------------------------------------------------- */
405
406/* Macro to convert a value to string in the preprocessor:
407 * - `STRINGIFY_ARG`: gives the argument as a string
408 * - `STRINGIFY_APPEND`: appends any argument 'b' onto the string argument 'a',
409 * used by `STRINGIFY` because some preprocessors warn about zero arguments.
410 * - `STRINGIFY`: gives the argument's value as a string. */
411
412#define STRINGIFY_ARG(x) "" #x
413#define STRINGIFY_APPEND(a, b) "" a #b
414#define STRINGIFY(x) STRINGIFY_APPEND("", x)
415
416/* generic strcmp macros */
417#if defined(_MSC_VER)
418# define strcasecmp _stricmp
419# define strncasecmp _strnicmp
420#endif
421
422#define STREQ(a, b) (strcmp(a, b) == 0)
423#define STRCASEEQ(a, b) (strcasecmp(a, b) == 0)
424#define STREQLEN(a, b, n) (strncmp(a, b, n) == 0)
425#define STRCASEEQLEN(a, b, n) (strncasecmp(a, b, n) == 0)
426
427#define STRPREFIX(a, b) (strncmp((a), (b), strlen(b)) == 0)
428
430
431/* -------------------------------------------------------------------- */
434
435#ifndef __cplusplus
436/* UNUSED macro, for function argument */
437# if defined(__GNUC__) || defined(__clang__)
438# define UNUSED(x) UNUSED_##x __attribute__((__unused__))
439# elif defined(_MSC_VER)
440/* NOTE: This suppresses the warning for the line, not the attribute. */
441# define UNUSED(x) UNUSED_##x __pragma(warning(suppress : 4100))
442# else
443# define UNUSED(x) UNUSED_##x
444# endif
445#endif
446
451#if defined(__GNUC__) || defined(__clang__)
452# define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_##x
453#else
454# define UNUSED_FUNCTION(x) UNUSED_##x
455#endif
456
457#if defined(__GNUC__) || defined(__clang__)
458# define UNUSED_FUNCTION_WITH_RETURN_TYPE(rtype, x) __attribute__((__unused__)) rtype UNUSED_##x
459#else
460# define UNUSED_FUNCTION_WITH_RETURN_TYPE(rtype, x) rtype UNUSED_##x
461#endif
462
475
476#define _VA_UNUSED_VARS_1(a0) ((void)(a0))
477#define _VA_UNUSED_VARS_2(a0, b0) ((void)(a0), _VA_UNUSED_VARS_1(b0))
478#define _VA_UNUSED_VARS_3(a0, b0, c0) ((void)(a0), _VA_UNUSED_VARS_2(b0, c0))
479#define _VA_UNUSED_VARS_4(a0, b0, c0, d0) ((void)(a0), _VA_UNUSED_VARS_3(b0, c0, d0))
480#define _VA_UNUSED_VARS_5(a0, b0, c0, d0, e0) ((void)(a0), _VA_UNUSED_VARS_4(b0, c0, d0, e0))
481#define _VA_UNUSED_VARS_6(a0, b0, c0, d0, e0, f0) \
482 ((void)(a0), _VA_UNUSED_VARS_5(b0, c0, d0, e0, f0))
483#define _VA_UNUSED_VARS_7(a0, b0, c0, d0, e0, f0, g0) \
484 ((void)(a0), _VA_UNUSED_VARS_6(b0, c0, d0, e0, f0, g0))
485#define _VA_UNUSED_VARS_8(a0, b0, c0, d0, e0, f0, g0, h0) \
486 ((void)(a0), _VA_UNUSED_VARS_7(b0, c0, d0, e0, f0, g0, h0))
487#define _VA_UNUSED_VARS_9(a0, b0, c0, d0, e0, f0, g0, h0, i0) \
488 ((void)(a0), _VA_UNUSED_VARS_8(b0, c0, d0, e0, f0, g0, h0, i0))
489#define _VA_UNUSED_VARS_10(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0) \
490 ((void)(a0), _VA_UNUSED_VARS_9(b0, c0, d0, e0, f0, g0, h0, i0, j0))
491#define _VA_UNUSED_VARS_11(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0) \
492 ((void)(a0), _VA_UNUSED_VARS_10(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0))
493#define _VA_UNUSED_VARS_12(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0) \
494 ((void)(a0), _VA_UNUSED_VARS_11(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0))
495#define _VA_UNUSED_VARS_13(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0) \
496 ((void)(a0), _VA_UNUSED_VARS_12(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0))
497#define _VA_UNUSED_VARS_14(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0) \
498 ((void)(a0), _VA_UNUSED_VARS_13(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0))
499#define _VA_UNUSED_VARS_15(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0) \
500 ((void)(a0), _VA_UNUSED_VARS_14(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0))
501#define _VA_UNUSED_VARS_16(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0, p0) \
502 ((void)(a0), _VA_UNUSED_VARS_15(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0, p0))
503
504/* reusable ELEM macro */
505#define UNUSED_VARS(...) VA_NARGS_CALL_OVERLOAD(_VA_UNUSED_VARS_, __VA_ARGS__)
506
507/* for debug-only variables */
508#ifndef NDEBUG
509# define UNUSED_VARS_NDEBUG(...)
510#else
511# define UNUSED_VARS_NDEBUG UNUSED_VARS
512#endif
513
515
516/* -------------------------------------------------------------------- */
519
520/* hints for branch prediction, only use in code that runs a _lot_ where */
521#ifdef __GNUC__
522# define LIKELY(x) __builtin_expect(!!(x), 1)
523# define UNLIKELY(x) __builtin_expect(!!(x), 0)
524#else
525# define LIKELY(x) (x)
526# define UNLIKELY(x) (x)
527#endif
528
530
531/* -------------------------------------------------------------------- */
534
535/* Set flag from a single test */
536#define SET_FLAG_FROM_TEST(value, test, flag) \
537 { \
538 if (test) { \
539 (value) |= (flag); \
540 } \
541 else { \
542 (value) &= ~(flag); \
543 } \
544 } \
545 ((void)0)
546
548
549/* -------------------------------------------------------------------- */
552
553#ifdef __cplusplus
554
555/* Useful to port C code using enums to C++ where enums are strongly typed.
556 * To use after the enum declaration. */
557/* If any enumerator `C` is set to say `A|B`, then `C` would be the max enum value. */
558# define ENUM_OPERATORS(_enum_type, _max_enum_value) \
559 extern "C++" { \
560 inline constexpr _enum_type operator|(_enum_type a, _enum_type b) \
561 { \
562 return (_enum_type)(uint64_t(a) | uint64_t(b)); \
563 } \
564 inline constexpr _enum_type operator&(_enum_type a, _enum_type b) \
565 { \
566 return (_enum_type)(uint64_t(a) & uint64_t(b)); \
567 } \
568 inline constexpr _enum_type operator~(_enum_type a) \
569 { \
570 return (_enum_type)(~uint64_t(a) & (2 * uint64_t(_max_enum_value) - 1)); \
571 } \
572 inline _enum_type &operator|=(_enum_type &a, _enum_type b) \
573 { \
574 return a = (_enum_type)(uint64_t(a) | uint64_t(b)); \
575 } \
576 inline _enum_type &operator&=(_enum_type &a, _enum_type b) \
577 { \
578 return a = (_enum_type)(uint64_t(a) & uint64_t(b)); \
579 } \
580 inline _enum_type &operator^=(_enum_type &a, _enum_type b) \
581 { \
582 return a = (_enum_type)(uint64_t(a) ^ uint64_t(b)); \
583 } \
584 } /* extern "C++" */
585
586#else
587/* Output nothing. */
588# define ENUM_OPERATORS(_type, _max)
589#endif
590
592
593/* -------------------------------------------------------------------- */
596
598#define AT __FILE__ ":" STRINGIFY(__LINE__)
599
601#define EXPR_NOP(expr) (void)(0 ? ((void)(expr), 1) : 0)
602
610#define BLI_ENABLE_IF(condition) typename std::enable_if_t<(condition)> * = nullptr
611
612#if defined(_MSC_VER) && !defined(__clang__)
613# define BLI_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
614#elif defined(__has_cpp_attribute)
615# if __has_cpp_attribute(no_unique_address)
616# define BLI_NO_UNIQUE_ADDRESS [[no_unique_address]]
617# else
618# define BLI_NO_UNIQUE_ADDRESS
619# endif
620#else
621# define BLI_NO_UNIQUE_ADDRESS [[no_unique_address]]
622#endif
623
625
626#ifdef __cplusplus
627}
628
629namespace blender::blenlib_internal {
630
631/* A replacement for std::is_bounded_array_v until we go C++20. */
632template<class T> struct IsBoundedArray : std::false_type {};
633template<class T, std::size_t N> struct IsBoundedArray<T[N]> : std::true_type {};
634
635} // namespace blender::blenlib_internal
636
643template<class T, size_t N> constexpr size_t ARRAY_SIZE(const T (&arg)[N]) noexcept
644{
645 (void)arg;
646 return N;
647}
648
659template<class T>
660constexpr std::enable_if_t<blender::blenlib_internal::IsBoundedArray<T>::value, size_t>
661BOUNDED_ARRAY_TYPE_SIZE() noexcept
662{
663 return sizeof(std::declval<T>()) / sizeof(std::declval<T>()[0]);
664}
665
666#endif
667
668#endif /* __BLI_UTILDEFINES_H__ */
#define BLI_assert(a)
Definition BLI_assert.h:46
bool BLI_memory_is_zero(const void *arr, size_t arr_size)
#define ARRAY_SIZE(arr)
long long int int64_t
#define N
#define T