Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2017-11-22 19:26:00 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-11-22 19:26:00 +0300
commit73c4ba18d50bc03465927e22b5d0085bf7d523a2 (patch)
tree17d1877bd52ae5e3598e16cb52f42f3be17a9125 /source/blender/blenlib
parent15a0ad602746bd8dd7dde3822d54979e72ca9de2 (diff)
parent326efb431971e668a41d9a331ccc3d11f9fd3e5f (diff)
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_utildefines.h25
1 files changed, 17 insertions, 8 deletions
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index 8f8d7cc3b7f..ec6042637aa 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -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); \