To clarify, the example is obviously incomplete. The idea would be for Vec and its specialization to enable iteration so that VecBase provides the implicit conversion on top.

Just search for "mixin" and "CRTP" and you'll find more in-depth information.

On Mon, 21 Jul 2025 at 21:25, Jan Schultke <janschultke@googlemail.com> wrote:
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.