BLI_utildefines: Support SWAP macro with two args

This commit is contained in:
Campbell Barton 2017-11-23 02:44:02 +11:00
parent 69b5165902
commit d749320e3b
Notes: blender-bot 2023-02-14 11:28:39 +01:00
Referenced by commit 434ed96dd2, Revert "BLI_utildefines: Support SWAP macro with two args"
Referenced by issue #53683, 2.79a release
1 changed files with 17 additions and 8 deletions

View File

@ -140,16 +140,25 @@ extern "C" {
/* some math and copy defines */
#define SWAP(type, a, b) { \
type sw_ap; \
CHECK_TYPE(a, type); \
CHECK_TYPE(b, type); \
sw_ap = (a); \
(a) = (b); \
(b) = sw_ap; \
#define _VA_SWAP3(type, a, b) { \
CHECK_TYPE(a, type); \
CHECK_TYPE(b, type); \
type SWAP = (a); \
(a) = (b); \
(b) = SWAP; \
} (void)0
#define _VA_SWAP2(a, b) { \
CHECK_TYPE_PAIR(a, b); \
struct { char a_[sizeof(a)]; } SWAP, *a_ = (void *)&(a), *b_ = (void *)&(b); \
SWAP = *a_; \
*a_ = *b_; \
*b_ = SWAP; \
} ((void)0)
/* SWAP with two or three args (initial type argument is optional) */
#define SWAP(...) VA_NARGS_CALL_OVERLOAD(_VA_SWAP, __VA_ARGS__)
/* swap with a temp value */
#define SWAP_TVAL(tval, a, b) { \
CHECK_TYPE_PAIR(tval, a); \