From 2643cb0e3c9b241f4e73c9cf40bd766fda0c01f1 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 1 Apr 2014 11:39:35 +0900 Subject: [PATCH] add SWAP macro --- include/picrin/util.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/picrin/util.h b/include/picrin/util.h index 3475caae..1ad80950 100644 --- a/include/picrin/util.h +++ b/include/picrin/util.h @@ -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