summaryrefslogtreecommitdiff
path: root/utils/swap_pod.h
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-11 02:46:13 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-11 02:46:13 +0000
commit82384b4ec365f3d2ad2c9bca078a0b38d4be09c0 (patch)
treef6f015f2791ec9b1ec94c90c98b09c0d251aee9e /utils/swap_pod.h
parente4e66118c14704509e214aa32689ef304ae5ada2 (diff)
merge
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@511 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'utils/swap_pod.h')
-rwxr-xr-xutils/swap_pod.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/utils/swap_pod.h b/utils/swap_pod.h
new file mode 100755
index 00000000..bb9a830d
--- /dev/null
+++ b/utils/swap_pod.h
@@ -0,0 +1,23 @@
+#ifndef SWAP_POD_H
+#define SWAP_POD_H
+
+//for swapping objects of the same concrete type where just swapping their bytes will work. will at least work on plain old data.
+
+#include <algorithm> // not used, but people who use this will want to bring std::swap in anyway
+#include <cstring>
+
+template <class T>
+inline void swap_pod(T &a,T &b) {
+ using namespace std;
+ const unsigned s=sizeof(T);
+ char tmp[s];
+ void *pt=(void*)tmp;
+ void *pa=(void*)&a;
+ void *pb=(void*)&b;
+ memcpy(pt,pa,s);
+ memcpy(pa,pb,s);
+ memcpy(pb,pt,s);
+}
+
+
+#endif