From 73633535288711de4850b9d9eec6326eb5de06c0 Mon Sep 17 00:00:00 2001 From: Siddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com> Date: Thu, 24 Apr 2025 11:02:23 -0400 Subject: Template files for vectors to override arithmetic operations --- inc/vec.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 inc/vec.h (limited to 'inc/vec.h') diff --git a/inc/vec.h b/inc/vec.h new file mode 100644 index 0000000..68482d5 --- /dev/null +++ b/inc/vec.h @@ -0,0 +1,44 @@ +// vec.h +#ifndef VEC_H +#define VEC_H + +#include +#include +#include + +template +class Vec { +private: + std::vector data; + +public: + Vec() = default; + Vec(const std::vector& values) : data(values) {} + + // Vector-Vector Operations + Vec operator+(const Vec& other) const; + Vec operator-(const Vec& other) const; + Vec operator*(const Vec& other) const; + Vec operator/(const Vec& other) const; + Vec operator%(const Vec& other) const; + + // Vector-Scalar Operations + Vec operator+(T scalar) const; + Vec operator-(T scalar) const; + Vec operator*(T scalar) const; + Vec operator/(T scalar) const; + Vec operator%(T scalar) const; + + // Utility + void print() const; + size_t size() const { return data.size(); } + + // Friend scalar-vector operations + friend Vec operator+(T scalar, const Vec& vec) { return vec + scalar; } + friend Vec operator-(T scalar, const Vec& vec); + friend Vec operator*(T scalar, const Vec& vec) { return vec * scalar; } + friend Vec operator/(T scalar, const Vec& vec); + friend Vec operator%(T scalar, const Vec& vec); +}; + +#endif -- cgit v1.2.3