From c8920ea9977db77861de2efd753825a5acf04389 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 28 Oct 2016 22:20:23 +0200 Subject: [PATCH] Implementation of vector_cast that works with vwr::Vec. --- src/vector.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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