diff options
author | Siddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com> | 2025-04-24 11:02:23 -0400 |
---|---|---|
committer | Siddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com> | 2025-04-24 11:02:23 -0400 |
commit | 73633535288711de4850b9d9eec6326eb5de06c0 (patch) | |
tree | 9897c058f808e06f1ab3a71bc988d07d72cbb60e /inc | |
parent | 8e33ba4499bced747f66ed436211876d220342d6 (diff) |
Template files for vectors to override arithmetic operations
Diffstat (limited to 'inc')
-rw-r--r-- | inc/vec.h | 44 |
1 files changed, 44 insertions, 0 deletions
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 <iostream> +#include <vector> +#include <stdexcept> + +template<typename T> +class Vec { +private: + std::vector<T> data; + +public: + Vec() = default; + Vec(const std::vector<T>& values) : data(values) {} + + // Vector-Vector Operations + Vec<T> operator+(const Vec<T>& other) const; + Vec<T> operator-(const Vec<T>& other) const; + Vec<T> operator*(const Vec<T>& other) const; + Vec<T> operator/(const Vec<T>& other) const; + Vec<T> operator%(const Vec<T>& other) const; + + // Vector-Scalar Operations + Vec<T> operator+(T scalar) const; + Vec<T> operator-(T scalar) const; + Vec<T> operator*(T scalar) const; + Vec<T> operator/(T scalar) const; + Vec<T> operator%(T scalar) const; + + // Utility + void print() const; + size_t size() const { return data.size(); } + + // Friend scalar-vector operations + friend Vec<T> operator+(T scalar, const Vec<T>& vec) { return vec + scalar; } + friend Vec<T> operator-(T scalar, const Vec<T>& vec); + friend Vec<T> operator*(T scalar, const Vec<T>& vec) { return vec * scalar; } + friend Vec<T> operator/(T scalar, const Vec<T>& vec); + friend Vec<T> operator%(T scalar, const Vec<T>& vec); +}; + +#endif |