Blender V5.3
BLI_utildefines.hh
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#pragma once
6
10
11/* avoid many includes for now */
13#include "BLI_sys_types.hh"
14#include "BLI_utildefines_variadic.hh" // IWYU prama: export
15
16/* We could remove in future. */
17#include "BLI_assert.hh"
18
19/* include after _VA_NARGS macro */
21
22#include <type_traits>
23#include <utility>
24
25namespace blender {
26
27/* -------------------------------------------------------------------- */
30
31#define INIT_MINMAX(min, max) \
32 { \
33 (min)[0] = (min)[1] = (min)[2] = 1.0e30f; \
34 (max)[0] = (max)[1] = (max)[2] = -1.0e30f; \
35 } \
36 (void)0
37#define INIT_MINMAX2(min, max) \
38 { \
39 (min)[0] = (min)[1] = 1.0e30f; \
40 (max)[0] = (max)[1] = -1.0e30f; \
41 } \
42 (void)0
43
45
46/* -------------------------------------------------------------------- */
49
50#define SWAP(type, a, b) \
51 { \
52 type sw_ap; \
53 CHECK_TYPE(a, type); \
54 CHECK_TYPE(b, type); \
55 sw_ap = (a); \
56 (a) = (b); \
57 (b) = sw_ap; \
58 } \
59 (void)0
60
61/* shift around elements */
62#define SHIFT3(type, a, b, c) \
63 { \
64 type tmp; \
65 CHECK_TYPE(a, type); \
66 CHECK_TYPE(b, type); \
67 CHECK_TYPE(c, type); \
68 tmp = a; \
69 a = c; \
70 c = b; \
71 b = tmp; \
72 } \
73 (void)0
74
75#define SHIFT4(type, a, b, c, d) \
76 { \
77 type tmp; \
78 CHECK_TYPE(a, type); \
79 CHECK_TYPE(b, type); \
80 CHECK_TYPE(c, type); \
81 CHECK_TYPE(d, type); \
82 tmp = a; \
83 a = d; \
84 d = c; \
85 c = b; \
86 b = tmp; \
87 } \
88 (void)0
89
91
92/* -------------------------------------------------------------------- */
95
96/* Manual line breaks for readability. */
97/* clang-format off */
98
99/* ELEM#(v, ...): is the first arg equal any others? */
100/* internal helpers. */
101#define _VA_ELEM2(v, a) ((v) == (a))
102#define _VA_ELEM3(v, a, b) \
103 (_VA_ELEM2(v, a) || _VA_ELEM2(v, b))
104#define _VA_ELEM4(v, a, b, c) \
105 (_VA_ELEM3(v, a, b) || _VA_ELEM2(v, c))
106#define _VA_ELEM5(v, a, b, c, d) \
107 (_VA_ELEM4(v, a, b, c) || _VA_ELEM2(v, d))
108#define _VA_ELEM6(v, a, b, c, d, e) \
109 (_VA_ELEM5(v, a, b, c, d) || _VA_ELEM2(v, e))
110#define _VA_ELEM7(v, a, b, c, d, e, f) \
111 (_VA_ELEM6(v, a, b, c, d, e) || _VA_ELEM2(v, f))
112#define _VA_ELEM8(v, a, b, c, d, e, f, g) \
113 (_VA_ELEM7(v, a, b, c, d, e, f) || _VA_ELEM2(v, g))
114#define _VA_ELEM9(v, a, b, c, d, e, f, g, h) \
115 (_VA_ELEM8(v, a, b, c, d, e, f, g) || _VA_ELEM2(v, h))
116#define _VA_ELEM10(v, a, b, c, d, e, f, g, h, i) \
117 (_VA_ELEM9(v, a, b, c, d, e, f, g, h) || _VA_ELEM2(v, i))
118#define _VA_ELEM11(v, a, b, c, d, e, f, g, h, i, j) \
119 (_VA_ELEM10(v, a, b, c, d, e, f, g, h, i) || _VA_ELEM2(v, j))
120#define _VA_ELEM12(v, a, b, c, d, e, f, g, h, i, j, k) \
121 (_VA_ELEM11(v, a, b, c, d, e, f, g, h, i, j) || _VA_ELEM2(v, k))
122#define _VA_ELEM13(v, a, b, c, d, e, f, g, h, i, j, k, l) \
123 (_VA_ELEM12(v, a, b, c, d, e, f, g, h, i, j, k) || _VA_ELEM2(v, l))
124#define _VA_ELEM14(v, a, b, c, d, e, f, g, h, i, j, k, l, m) \
125 (_VA_ELEM13(v, a, b, c, d, e, f, g, h, i, j, k, l) || _VA_ELEM2(v, m))
126#define _VA_ELEM15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
127 (_VA_ELEM14(v, a, b, c, d, e, f, g, h, i, j, k, l, m) || _VA_ELEM2(v, n))
128#define _VA_ELEM16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \
129 (_VA_ELEM15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n) || _VA_ELEM2(v, o))
130#define _VA_ELEM17(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
131 (_VA_ELEM16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) || _VA_ELEM2(v, p))
132/* clang-format on */
133
134/* reusable ELEM macro */
135#define ELEM(...) VA_NARGS_CALL_OVERLOAD(_VA_ELEM, __VA_ARGS__)
136
138
139/* -------------------------------------------------------------------- */
142
143/* Float equality checks. */
144
145#define IS_EQ(a, b) \
146 (CHECK_TYPE_INLINE_NONCONST(a, double), \
147 CHECK_TYPE_INLINE_NONCONST(b, double), \
148 ((fabs((double)((a) - (b))) >= (double)FLT_EPSILON) ? false : true))
149
150#define IS_EQF(a, b) \
151 (CHECK_TYPE_INLINE_NONCONST(a, float), \
152 CHECK_TYPE_INLINE_NONCONST(b, float), \
153 ((fabsf((float)((a) - (b))) >= (float)FLT_EPSILON) ? false : true))
154
155#define IS_EQT(a, b, c) (((a) > (b)) ? ((((a) - (b)) <= (c))) : (((((b) - (a)) <= (c)))))
156#define IN_RANGE(a, b, c) (((b) < (c)) ? (((b) < (a) && (a) < (c))) : (((c) < (a) && (a) < (b))))
157#define IN_RANGE_INCL(a, b, c) \
158 (((b) < (c)) ? (((b) <= (a) && (a) <= (c))) : (((c) <= (a) && (a) <= (b))))
159
168#define DECIMAL_DIGITS_BOUND(t) (241 * sizeof(t) / 100 + 1)
169
171{
172 BLI_assert(x >= 0);
173 return (x & (x - 1)) == 0;
174}
175
176constexpr int64_t log2_floor(const int64_t x)
177{
178 BLI_assert(x >= 0);
179 return x <= 1 ? 0 : 1 + log2_floor(x >> 1);
180}
181
182constexpr int64_t log2_ceil(const int64_t x)
183{
184 BLI_assert(x >= 0);
185 return (is_power_of_2(int(x))) ? log2_floor(x) : log2_floor(x) + 1;
186}
187
189{
190 BLI_assert(x >= 0);
191 return 1ll << log2_ceil(x);
192}
193
195
196/* -------------------------------------------------------------------- */
199
200#define CLAMP(a, b, c) \
201 { \
202 if ((a) < (b)) { \
203 (a) = (b); \
204 } \
205 else if ((a) > (c)) { \
206 (a) = (c); \
207 } \
208 } \
209 (void)0
210
211#define CLAMP_MAX(a, c) \
212 { \
213 if ((a) > (c)) { \
214 (a) = (c); \
215 } \
216 } \
217 (void)0
218
219#define CLAMP_MIN(a, b) \
220 { \
221 if ((a) < (b)) { \
222 (a) = (b); \
223 } \
224 } \
225 (void)0
226
228
229/* -------------------------------------------------------------------- */
232
233/* unpack vector for args */
234#define UNPACK2(a) ((a)[0]), ((a)[1])
235#define UNPACK3(a) UNPACK2(a), ((a)[2])
236#define UNPACK4(a) UNPACK3(a), ((a)[3])
237/* pre may be '&', '*' or func, post may be '->member' */
238#define UNPACK2_EX(pre, a, post) (pre((a)[0]) post), (pre((a)[1]) post)
239#define UNPACK3_EX(pre, a, post) UNPACK2_EX(pre, a, post), (pre((a)[2]) post)
240#define UNPACK4_EX(pre, a, post) UNPACK3_EX(pre, a, post), (pre((a)[3]) post)
241
243
244/* -------------------------------------------------------------------- */
247
248#define ARRAY_HAS_ITEM(arr_item, arr_start, arr_len) \
249 (CHECK_TYPE_PAIR_INLINE(arr_start, arr_item), \
250 ((size_t)((arr_item) - (arr_start)) < (size_t)(arr_len)))
251
252/* assuming a static array */
253
254/* ARRAY_SET_ITEMS#(v, ...): set indices of array 'v' */
255/* internal helpers */
256#define _VA_ARRAY_SET_ITEMS2(v, a) ((v)[0] = (a))
257#define _VA_ARRAY_SET_ITEMS3(v, a, b) \
258 _VA_ARRAY_SET_ITEMS2(v, a); \
259 ((v)[1] = (b))
260#define _VA_ARRAY_SET_ITEMS4(v, a, b, c) \
261 _VA_ARRAY_SET_ITEMS3(v, a, b); \
262 ((v)[2] = (c))
263#define _VA_ARRAY_SET_ITEMS5(v, a, b, c, d) \
264 _VA_ARRAY_SET_ITEMS4(v, a, b, c); \
265 ((v)[3] = (d))
266#define _VA_ARRAY_SET_ITEMS6(v, a, b, c, d, e) \
267 _VA_ARRAY_SET_ITEMS5(v, a, b, c, d); \
268 ((v)[4] = (e))
269#define _VA_ARRAY_SET_ITEMS7(v, a, b, c, d, e, f) \
270 _VA_ARRAY_SET_ITEMS6(v, a, b, c, d, e); \
271 ((v)[5] = (f))
272#define _VA_ARRAY_SET_ITEMS8(v, a, b, c, d, e, f, g) \
273 _VA_ARRAY_SET_ITEMS7(v, a, b, c, d, e, f); \
274 ((v)[6] = (g))
275#define _VA_ARRAY_SET_ITEMS9(v, a, b, c, d, e, f, g, h) \
276 _VA_ARRAY_SET_ITEMS8(v, a, b, c, d, e, f, g); \
277 ((v)[7] = (h))
278#define _VA_ARRAY_SET_ITEMS10(v, a, b, c, d, e, f, g, h, i) \
279 _VA_ARRAY_SET_ITEMS9(v, a, b, c, d, e, f, g, h); \
280 ((v)[8] = (i))
281#define _VA_ARRAY_SET_ITEMS11(v, a, b, c, d, e, f, g, h, i, j) \
282 _VA_ARRAY_SET_ITEMS10(v, a, b, c, d, e, f, g, h, i); \
283 ((v)[9] = (j))
284#define _VA_ARRAY_SET_ITEMS12(v, a, b, c, d, e, f, g, h, i, j, k) \
285 _VA_ARRAY_SET_ITEMS11(v, a, b, c, d, e, f, g, h, i, j); \
286 ((v)[10] = (k))
287#define _VA_ARRAY_SET_ITEMS13(v, a, b, c, d, e, f, g, h, i, j, k, l) \
288 _VA_ARRAY_SET_ITEMS12(v, a, b, c, d, e, f, g, h, i, j, k); \
289 ((v)[11] = (l))
290#define _VA_ARRAY_SET_ITEMS14(v, a, b, c, d, e, f, g, h, i, j, k, l, m) \
291 _VA_ARRAY_SET_ITEMS13(v, a, b, c, d, e, f, g, h, i, j, k, l); \
292 ((v)[12] = (m))
293#define _VA_ARRAY_SET_ITEMS15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
294 _VA_ARRAY_SET_ITEMS14(v, a, b, c, d, e, f, g, h, i, j, k, l, m); \
295 ((v)[13] = (n))
296#define _VA_ARRAY_SET_ITEMS16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \
297 _VA_ARRAY_SET_ITEMS15(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n); \
298 ((v)[14] = (o))
299#define _VA_ARRAY_SET_ITEMS17(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
300 _VA_ARRAY_SET_ITEMS16(v, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o); \
301 ((v)[15] = (p))
302
303/* reusable ARRAY_SET_ITEMS macro */
304#define ARRAY_SET_ITEMS(...) \
305 { \
306 VA_NARGS_CALL_OVERLOAD(_VA_ARRAY_SET_ITEMS, __VA_ARGS__); \
307 } \
308 (void)0
309
311
312/* -------------------------------------------------------------------- */
315
316#define POINTER_OFFSET(v, ofs) \
317 (reinterpret_cast<std::remove_reference_t<decltype(v)>>((char *)(v) + (ofs)))
318
319/* Warning-free macros for storing ints in pointers. Use these _only_
320 * for storing an int in a pointer, not a pointer in an int (64bit)! */
321#define POINTER_FROM_INT(i) ((void *)(intptr_t)(i))
322#define POINTER_AS_INT(i) ((void)0, ((int)(intptr_t)(i)))
323
324#define POINTER_FROM_UINT(i) ((void *)(uintptr_t)(i))
325#define POINTER_AS_UINT(i) ((void)0, ((unsigned int)(uintptr_t)(i)))
326
328
329/* -------------------------------------------------------------------- */
336
338#define OFFSETOF_STRUCT_AFTER(_struct, _member) \
339 ((size_t)(((const char *)&((_struct)->_member)) - ((const char *)(_struct))) + \
340 sizeof((_struct)->_member))
341
347#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member) \
348 { \
349 CHECK_TYPE_NONCONST(struct_dst); \
350 ((void)(struct_dst == struct_src), \
351 memcpy((char *)(struct_dst) + OFFSETOF_STRUCT_AFTER(struct_dst, member), \
352 (const char *)(struct_src) + OFFSETOF_STRUCT_AFTER(struct_dst, member), \
353 sizeof(*(struct_dst)) - OFFSETOF_STRUCT_AFTER(struct_dst, member))); \
354 } \
355 ((void)0)
356
357#define MEMSET_STRUCT_AFTER(struct_var, value, member) \
358 { \
359 CHECK_TYPE_NONCONST(struct_var); \
360 memset((char *)(struct_var) + OFFSETOF_STRUCT_AFTER(struct_var, member), \
361 value, \
362 sizeof(*(struct_var)) - OFFSETOF_STRUCT_AFTER(struct_var, member)); \
363 } \
364 ((void)0)
365
375constexpr bool memory_is_zero(const void *data, const size_t size)
376{
377 const char *arr_byte = static_cast<const char *>(data);
378 const char *arr_end = static_cast<const char *>(data) + size;
379
380 while ((arr_byte != arr_end) && (*arr_byte == 0)) {
381 arr_byte++;
382 }
383
384 return (arr_byte == arr_end);
385}
386
394template<typename T> constexpr bool value_is_zero_memory(const T &value)
395{
396 if constexpr (std::is_pointer_v<T>) {
397 return value == nullptr;
398 }
399 else if constexpr (std::is_integral_v<T>) {
400 return value == 0;
401 }
402 else if constexpr (std::is_floating_point_v<T>) {
403 return value == 0.0f;
404 }
405 else if constexpr (std::has_unique_object_representations_v<T>) {
406 return memory_is_zero(&value, sizeof(T));
407 }
408 else {
409 /* Can't use #memory_is_zero here without invoking undefined behavior. Other types can overload
410 * the #value_is_zero_memory function. Also see #161759. */
411 return false;
412 }
413}
414
415#define MEMCMP_STRUCT_AFTER_IS_ZERO_OR_EQUAL(struct_dst, struct_src, member) \
416 (memory_is_zero((const char *)(struct_dst) + OFFSETOF_STRUCT_AFTER(struct_dst, member), \
417 sizeof(*(struct_dst)) - OFFSETOF_STRUCT_AFTER(struct_dst, member)) || \
418 (memcmp((const char *)(struct_dst) + OFFSETOF_STRUCT_AFTER(struct_dst, member), \
419 (const char *)(struct_src) + OFFSETOF_STRUCT_AFTER(struct_src, member), \
420 sizeof(*(struct_dst)) - OFFSETOF_STRUCT_AFTER(struct_dst, member)) == 0))
421
422#define INIT_DEFAULT_STRUCT_AFTER(struct_dst, member) \
423 { \
424 const typename std::remove_reference<decltype(*(struct_dst))>::type struct_src; \
425 BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO_OR_EQUAL(struct_dst, &struct_src, member)); \
426 MEMCPY_STRUCT_AFTER(struct_dst, &struct_src, member); \
427 }
428
430
431/* -------------------------------------------------------------------- */
434
435/* Macro to convert a value to string in the preprocessor:
436 * - `STRINGIFY_ARG`: gives the argument as a string
437 * - `STRINGIFY_APPEND`: appends any argument 'b' onto the string argument 'a',
438 * used by `STRINGIFY` because some preprocessors warn about zero arguments.
439 * - `STRINGIFY`: gives the argument's value as a string. */
440
441#define STRINGIFY_ARG(x) "" #x
442#define STRINGIFY_APPEND(a, b) "" a #b
443#define STRINGIFY(x) STRINGIFY_APPEND("", x)
444
445/* generic strcmp macros */
446#if defined(_MSC_VER)
447# define strcasecmp _stricmp
448# define strncasecmp _strnicmp
449#endif
450
451#define STREQ(a, b) (strcmp(a, b) == 0)
452#define STRCASEEQ(a, b) (strcasecmp(a, b) == 0)
453#define STREQLEN(a, b, n) (strncmp(a, b, n) == 0)
454#define STRCASEEQLEN(a, b, n) (strncasecmp(a, b, n) == 0)
455
456#define STRPREFIX(a, b) (strncmp((a), (b), strlen(b)) == 0)
457
459
460/* -------------------------------------------------------------------- */
463
468#if defined(__GNUC__) || defined(__clang__)
469# define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_##x
470#else
471# define UNUSED_FUNCTION(x) UNUSED_##x
472#endif
473
474#if defined(__GNUC__) || defined(__clang__)
475# define UNUSED_FUNCTION_WITH_RETURN_TYPE(rtype, x) __attribute__((__unused__)) rtype UNUSED_##x
476#else
477# define UNUSED_FUNCTION_WITH_RETURN_TYPE(rtype, x) rtype UNUSED_##x
478#endif
479
492
493#define _VA_UNUSED_VARS_1(a0) ((void)(a0))
494#define _VA_UNUSED_VARS_2(a0, b0) ((void)(a0), _VA_UNUSED_VARS_1(b0))
495#define _VA_UNUSED_VARS_3(a0, b0, c0) ((void)(a0), _VA_UNUSED_VARS_2(b0, c0))
496#define _VA_UNUSED_VARS_4(a0, b0, c0, d0) ((void)(a0), _VA_UNUSED_VARS_3(b0, c0, d0))
497#define _VA_UNUSED_VARS_5(a0, b0, c0, d0, e0) ((void)(a0), _VA_UNUSED_VARS_4(b0, c0, d0, e0))
498#define _VA_UNUSED_VARS_6(a0, b0, c0, d0, e0, f0) \
499 ((void)(a0), _VA_UNUSED_VARS_5(b0, c0, d0, e0, f0))
500#define _VA_UNUSED_VARS_7(a0, b0, c0, d0, e0, f0, g0) \
501 ((void)(a0), _VA_UNUSED_VARS_6(b0, c0, d0, e0, f0, g0))
502#define _VA_UNUSED_VARS_8(a0, b0, c0, d0, e0, f0, g0, h0) \
503 ((void)(a0), _VA_UNUSED_VARS_7(b0, c0, d0, e0, f0, g0, h0))
504#define _VA_UNUSED_VARS_9(a0, b0, c0, d0, e0, f0, g0, h0, i0) \
505 ((void)(a0), _VA_UNUSED_VARS_8(b0, c0, d0, e0, f0, g0, h0, i0))
506#define _VA_UNUSED_VARS_10(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0) \
507 ((void)(a0), _VA_UNUSED_VARS_9(b0, c0, d0, e0, f0, g0, h0, i0, j0))
508#define _VA_UNUSED_VARS_11(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0) \
509 ((void)(a0), _VA_UNUSED_VARS_10(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0))
510#define _VA_UNUSED_VARS_12(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0) \
511 ((void)(a0), _VA_UNUSED_VARS_11(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0))
512#define _VA_UNUSED_VARS_13(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0) \
513 ((void)(a0), _VA_UNUSED_VARS_12(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0))
514#define _VA_UNUSED_VARS_14(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0) \
515 ((void)(a0), _VA_UNUSED_VARS_13(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0))
516#define _VA_UNUSED_VARS_15(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0) \
517 ((void)(a0), _VA_UNUSED_VARS_14(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0))
518#define _VA_UNUSED_VARS_16(a0, b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0, p0) \
519 ((void)(a0), _VA_UNUSED_VARS_15(b0, c0, d0, e0, f0, g0, h0, i0, j0, k0, l0, m0, n0, o0, p0))
520
521/* reusable ELEM macro */
522#define UNUSED_VARS(...) VA_NARGS_CALL_OVERLOAD(_VA_UNUSED_VARS_, __VA_ARGS__)
523
524/* for debug-only variables */
525#ifndef NDEBUG
526# define UNUSED_VARS_NDEBUG(...)
527#else
528# define UNUSED_VARS_NDEBUG UNUSED_VARS
529#endif
530
532
533/* -------------------------------------------------------------------- */
536
537/* Hints for branch prediction.
538 *
539 * NOTE: prefer C++ `[[likely]]` / `[[unlikely]]` attribute.
540 * Use the defines in contexts where attributes aren't supported (ternary operators for e.g.).
541 */
542#ifdef __GNUC__
543# define LIKELY(x) __builtin_expect(!!(x), 1)
544# define UNLIKELY(x) __builtin_expect(!!(x), 0)
545#else
546# define LIKELY(x) (x)
547# define UNLIKELY(x) (x)
548#endif
549
551
552/* -------------------------------------------------------------------- */
555
556/* Set flag from a single test */
557#define SET_FLAG_FROM_TEST(value, test, flag) \
558 { \
559 if (test) { \
560 (value) |= (flag); \
561 } \
562 else { \
563 (value) &= ~(flag); \
564 } \
565 } \
566 ((void)0)
567
569
570/* -------------------------------------------------------------------- */
573
575#define AT __FILE__ ":" STRINGIFY(__LINE__)
576
578#define EXPR_NOP(expr) (void)(0 ? ((void)(expr), 1) : 0)
579
580#if defined(_MSC_VER) && !defined(__clang__)
581# define BLI_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
582#elif defined(__has_cpp_attribute)
583# if __has_cpp_attribute(no_unique_address)
584# define BLI_NO_UNIQUE_ADDRESS [[no_unique_address]]
585# else
586# define BLI_NO_UNIQUE_ADDRESS
587# endif
588#else
589# define BLI_NO_UNIQUE_ADDRESS [[no_unique_address]]
590#endif
591
593
595
596/* A replacement for std::is_bounded_array_v until we go C++20. */
597template<class T> struct IsBoundedArray : std::false_type {};
598template<class T, std::size_t N> struct IsBoundedArray<T[N]> : std::true_type {};
599
600} // namespace blenlib_internal
601
608template<class T, size_t N> constexpr size_t ARRAY_SIZE(const T (&arg)[N]) noexcept
609{
610 (void)arg;
611 return N;
612}
613
624template<class T>
625constexpr std::enable_if_t<blenlib_internal::IsBoundedArray<T>::value, size_t>
627{
628 return sizeof(std::declval<T>()) / sizeof(std::declval<T>()[0]);
629}
630
631} // namespace blender
#define N
#define T
BMesh Iterators.
constexpr int64_t log2_floor(const int64_t x)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
constexpr int64_t power_of_2_max(const int64_t x)
constexpr bool value_is_zero_memory(const VecBase< T, Size > &v)
constexpr bool memory_is_zero(const void *data, const size_t size)
constexpr std::enable_if_t< blenlib_internal::IsBoundedArray< T >::value, size_t > BOUNDED_ARRAY_TYPE_SIZE() noexcept
constexpr int64_t log2_ceil(const int64_t x)
BMesh const char void * data
constexpr int64_t is_power_of_2(const int64_t x)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept