summaryrefslogtreecommitdiffstats
path: root/floatprops.h
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2013-07-03 15:42:56 -0400
committerErik Schnetter <schnetter@gmail.com>2013-07-03 15:42:56 -0400
commit2613760a8a5cf48e9f6d7462c7a844338c02ee61 (patch)
treeb3268791d2d0a3b7ff02e1834b56f05ab791d903 /floatprops.h
parent376ddd4a2c4a7226765ed965d7a220d9222e8b3f (diff)
downloadvecmathlib-2613760a8a5cf48e9f6d7462c7a844338c02ee61.zip
vecmathlib-2613760a8a5cf48e9f6d7462c7a844338c02ee61.tar.gz
Provide generic functions to extract elements from vectors
Diffstat (limited to 'floatprops.h')
-rw-r--r--floatprops.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/floatprops.h b/floatprops.h
index a232bd8..45d4fed 100644
--- a/floatprops.h
+++ b/floatprops.h
@@ -5,6 +5,7 @@
#include "floattypes.h"
+#include <cassert>
#include <cmath>
#include <cstring>
#include <iostream>
@@ -261,6 +262,28 @@ namespace vecmathlib {
+ // We are adding the (unused) type RV here to avoid name mangling
+ // problems. On some systems, the vector size does not enter into
+ // the mangled name (!), leading to duplicate function definitions.
+ template<typename RV, typename V, typename E>
+ E get_elt(const V& v, const int n)
+ {
+ const size_t s = sizeof(E);
+ E e;
+ // assert(n>=0 and s*n<sizeof(V));
+ std::memcpy(&e, &((const char*)&v)[s*n], s);
+ return e;
+ }
+
+ template<typename RV, typename V, typename E>
+ V& set_elt(V& v, const int n, const E e)
+ {
+ const size_t s = sizeof(E);
+ // assert(n>=0 and s*n<sizeof(V));
+ std::memcpy(&((char*)&v)[s*n], &e, s);
+ return v;
+ }
+
} // namespace vecmathlib
#endif // #ifndef FLOATPROPS_H
OpenPOWER on IntegriCloud