Closed m-tosch closed 3 years ago
also concerns matrix dot()
functions
the if constexpr() { ... }
part of the code is c++17
Update
replaced by using std::conditional
and a static_assert in #96
new code
template <typename U = void, std::size_t N2, typename T2>
std::conditional_t<std::is_same<U, void>::value, T, U> dot(
const Vector<N2, T2> &rhs) const {
static_assert(N == N2, "Vector size mismatch");
/* if the two types are not the same, use U which must not be void */
using cond1 = std::conditional_t<!std::is_same<T, T2>::value, U, T>;
static_assert(!std::is_same<cond1, void>::value,
"Vector types are different. please specify the return "
"type. e.g. \"vec1.dot<float>(vec2);\"");
using U_ = std::conditional_t<std::is_same<U, void>::value, T, U>;
U_ ret{};
for (std::size_t i = 0; i < N; i++) {
ret += data_[i] * rhs[i];
}
return ret;
}
could still use some clean up!
removed cond1
and used U_
in the static_assert directly (see commit below)
Vector
member functiondot()
contains some ugly code to make it work conveniently for different and same typed Vectorsmaybe the code can be cleaned up a little bit. maybe the static asserts can become SFINAE code ?