summaryrefslogtreecommitdiff
path: root/inc/vec.h
blob: 68482d5f43f9dc63b482b7b7cd1d503dee47ab6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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