Implementation of vector_cast that works with vwr::Vec.
This commit is contained in:
parent
629a3d9e08
commit
c8920ea997
1 changed files with 22 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
# include <iostream>
|
# include <iostream>
|
||||||
#endif
|
#endif
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#define SPECIALIZE_ARRAY_VECTOR(TYPE, DIM) \
|
#define SPECIALIZE_ARRAY_VECTOR(TYPE, DIM) \
|
||||||
template <> \
|
template <> \
|
||||||
|
@ -34,12 +35,33 @@ namespace vwr {
|
||||||
return parStream;
|
return parStream;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace implem {
|
||||||
|
template <typename TO, typename FROM, std::size_t... I>
|
||||||
|
Vec<TO> vector_cast (const Vec<FROM>& parVec, Vec<TO>*, std::index_sequence<I...>) {
|
||||||
|
static_assert(
|
||||||
|
static_cast<int>(Vec<TO>::dimensions) == static_cast<int>(Vec<FROM>::dimensions),
|
||||||
|
"Mismatching dimensions"
|
||||||
|
);
|
||||||
|
static_assert(sizeof...(I) == Vec<TO>::dimensions, "Mismatching index count");
|
||||||
|
typedef typename Vec<TO>::scalar_type CastType;
|
||||||
|
|
||||||
|
return Vec<TO>(static_cast<CastType>(parVec[I])...);
|
||||||
|
}
|
||||||
|
} //namespace implem
|
||||||
|
|
||||||
|
template <typename TOVec, typename FROM>
|
||||||
|
TOVec vector_cast (const Vec<FROM>& parVec) {
|
||||||
|
TOVec* const to = nullptr;
|
||||||
|
return implem::vector_cast(parVec, to, std::make_index_sequence<Vec<FROM>::dimensions>());
|
||||||
|
}
|
||||||
} //namespace vwr
|
} //namespace vwr
|
||||||
|
|
||||||
namespace curry {
|
namespace curry {
|
||||||
using vec2f = vwr::Vec<std::array<float, 2>>;
|
using vec2f = vwr::Vec<std::array<float, 2>>;
|
||||||
using vec2us = vwr::Vec<std::array<uint16_t, 2>>;
|
using vec2us = vwr::Vec<std::array<uint16_t, 2>>;
|
||||||
using vec2i = vwr::Vec<std::array<int32_t, 2>>;
|
using vec2i = vwr::Vec<std::array<int32_t, 2>>;
|
||||||
|
using vwr::vector_cast;
|
||||||
} //namespace curry
|
} //namespace curry
|
||||||
|
|
||||||
//make stuff from CloonelJump compile happily
|
//make stuff from CloonelJump compile happily
|
||||||
|
|
Loading…
Reference in a new issue