Date: Mon, 21 Jul 2025 21:25:57 +0200
What you're doing with your STAMP_MATH_VECTOR_TYPECAST_GENERIC macro seems
really unnecessary. If you have some common operations that are shared
among the primary template and various partial specializations, you can use
the good old mixin and CRTP idioms:
template<class Self>
struct VecBase {
explicit operator bool() const {
for (const auto& x : static_cast<const Self&>(*this))
if (!x) return false;
return true;
}
};
template<class T>
struct Vec : VecBase<Vec<T>> { };
template<>
struct Vec<int> : VecBase<Vec<T>> { };
So just do this.
I think it would introduce a lot of chaos into the language if anyone could
retroactively slap implicit conversions onto any type. I cannot come up
with a great example of maximal damage right now, but my intuition tells me
it's playing with fire.
really unnecessary. If you have some common operations that are shared
among the primary template and various partial specializations, you can use
the good old mixin and CRTP idioms:
template<class Self>
struct VecBase {
explicit operator bool() const {
for (const auto& x : static_cast<const Self&>(*this))
if (!x) return false;
return true;
}
};
template<class T>
struct Vec : VecBase<Vec<T>> { };
template<>
struct Vec<int> : VecBase<Vec<T>> { };
So just do this.
I think it would introduce a lot of chaos into the language if anyone could
retroactively slap implicit conversions onto any type. I cannot come up
with a great example of maximal damage right now, but my intuition tells me
it's playing with fire.
Received on 2025-07-21 19:26:13