add SWAP macro

This commit is contained in:
Yuichi Nishiwaki 2014-04-01 11:39:35 +09:00
parent cbcbd9e6c4
commit 2643cb0e3c
1 changed files with 9 additions and 0 deletions

View File

@ -35,6 +35,15 @@ extern "C" {
# define UNREACHABLE() (assert(false))
#endif
#define SWAP(type,a,b) \
SWAP_HELPER__(type,GENSYM(tmp),a,b)
#define SWAP_HELPER__(type,tmp,a,b) \
do { \
type tmp = (a); \
(a) = (b); \
(b) = tmp; \
} while (0)
#if defined(__cplusplus)
}
#endif