diff --git a/src/vector.hpp b/src/vector.hpp index cb863f6..afbf000 100644 --- a/src/vector.hpp +++ b/src/vector.hpp @@ -6,6 +6,7 @@ #if !defined(NDEBUG) # include #endif +#include #define SPECIALIZE_ARRAY_VECTOR(TYPE, DIM) \ template <> \ @@ -34,12 +35,33 @@ namespace vwr { return parStream; } #endif + + namespace implem { + template + Vec vector_cast (const Vec& parVec, Vec*, std::index_sequence) { + static_assert( + static_cast(Vec::dimensions) == static_cast(Vec::dimensions), + "Mismatching dimensions" + ); + static_assert(sizeof...(I) == Vec::dimensions, "Mismatching index count"); + typedef typename Vec::scalar_type CastType; + + return Vec(static_cast(parVec[I])...); + } + } //namespace implem + + template + TOVec vector_cast (const Vec& parVec) { + TOVec* const to = nullptr; + return implem::vector_cast(parVec, to, std::make_index_sequence::dimensions>()); + } } //namespace vwr namespace curry { using vec2f = vwr::Vec>; using vec2us = vwr::Vec>; using vec2i = vwr::Vec>; + using vwr::vector_cast; } //namespace curry //make stuff from CloonelJump compile happily