#include #include namespace math { template struct vec3 { T x; T y; T z; }; } template math::vec3 operator+(const math::vec3& a, const math::vec3& b) { math::vec3 res; res.x = a.x + b.x; res.y = a.y + b.y; res.z = a.z + b.z; return res; } template math::vec3 operator*(const T& scalar, const math::vec3& vec) { math::vec3 res; res.x = scalar * vec.x; res.y = scalar * vec.y; res.z = scalar * vec.z; return res; } template math::vec3 operator-(const math::vec3& a, const math::vec3& b) { return a + static_cast(-1) * b; } template std::ostream& operator<<(std::ostream& os, const math::vec3& vec) { os << "<" << vec.x << ", " << vec.y << ", " << vec.z << ">"; return os; } int main(int argc, char *argv[]) { // using numeric_type = std::complex; using numeric_type = int; math::vec3 a = {1, 2, 3}; math::vec3 b = {1, 2, 3}; std::cout << a + b << std::endl; std::cout << a - b << std::endl; std::cout << static_cast(2) * b << std::endl; return 0; }