Lugdunum  0.1.0
ValArray.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #define NOMINMAX
4 #include <algorithm>
5 #include <array>
6 #include <cstring>
7 #include <numeric>
8 
9 namespace lug {
10 namespace Math {
11 
12 template <size_t Size, typename T = float>
13 class ValArray {
14 public:
15  ValArray() = default;
16  explicit ValArray(const T& value);
17  explicit ValArray(const T* values);
18  ValArray(const ValArray<Size, T>& rhs) = default;
19  ValArray(ValArray<Size, T>&& rhs) = default;
20  ValArray(std::initializer_list<T> list);
21 
22  ValArray<Size, T>& operator=(const ValArray<Size, T>& rhs) = default;
24 
25  ~ValArray() = default;
26 
27  const T& operator[](size_t pos) const;
28  T& operator[](size_t pos);
29 
30  const std::array<T, Size>& data() const;
31  std::array<T, Size>& data();
32 
33  constexpr size_t size() const;
34 
35  T sum() const;
36 
37  // ValArray/Scalar operations
38  ValArray<Size, T>& operator+=(const T& rhs);
39  ValArray<Size, T>& operator-=(const T& rhs);
40  ValArray<Size, T>& operator*=(const T& rhs);
41  ValArray<Size, T>& operator/=(const T& rhs);
42 
43  // ValArray/ValArray operations
48 
49 private:
50  std::array<T, Size> _data;
51 };
52 
53 // ValArray/Scalar operations
54 template <size_t Size, typename T = float>
55 ValArray<Size, T> operator+(const ValArray<Size, T>& lhs, const T& rhs);
56 
57 template <size_t Size, typename T = float>
58 ValArray<Size, T> operator-(const ValArray<Size, T>& lhs, const T& rhs);
59 
60 template <size_t Size, typename T = float>
61 ValArray<Size, T> operator*(const ValArray<Size, T>& lhs, const T& rhs);
62 
63 template <size_t Size, typename T = float>
64 ValArray<Size, T> operator/(const ValArray<Size, T>& lhs, const T& rhs);
65 
66 template <size_t Size, typename T = float>
67 ValArray<Size, T> operator+(const T& lhs, const ValArray<Size, T>& rhs);
68 
69 template <size_t Size, typename T = float>
70 ValArray<Size, T> operator-(const T& lhs, const ValArray<Size, T>& rhs);
71 
72 template <size_t Size, typename T = float>
73 ValArray<Size, T> operator*(const T& lhs, const ValArray<Size, T>& rhs);
74 
75 template <size_t Size, typename T = float>
76 ValArray<Size, T> operator/(const T& lhs, const ValArray<Size, T>& rhs);
77 
78 // ValArray/ValArray operations
79 template <size_t Size, typename T = float>
81 
82 template <size_t Size, typename T = float>
84 
85 template <size_t Size, typename T = float>
87 
88 template <size_t Size, typename T = float>
90 
91 template <size_t Size, typename T = float>
92 bool operator==(const ValArray<Size, T>& lhs, const ValArray<Size, T>& rhs);
93 
94 template <size_t Size, typename T = float>
95 bool operator!=(const ValArray<Size, T>& lhs, const ValArray<Size, T>& rhs);
96 
97 #include <lug/Math/ValArray.inl>
98 
99 } // Math
100 } // lug
bool operator!=(const Matrix< Rows, Columns, T > &lhs, const Matrix< Rows, Columns, T > &rhs)
bool operator==(const Matrix< Rows, Columns, T > &lhs, const Matrix< Rows, Columns, T > &rhs)
ValArray< Size, T > & operator/=(const T &rhs)
Definition: ValArray.inl:75
ValArray< Size, T > & operator*=(const T &rhs)
Definition: ValArray.inl:66
std::array< T, Size > _data
Definition: ValArray.hpp:50
Matrix< Rows, Columns, T > operator-(const Matrix< Rows, Columns, T > &lhs)
ValArray< Size, T > & operator=(const ValArray< Size, T > &rhs)=default
ValArray< Size, T > & operator+=(const T &rhs)
Definition: ValArray.inl:48
Matrix< Rows, Columns, T > operator+(const Matrix< Rows, Columns, T > &lhs, T rhs)
const T & operator[](size_t pos) const
Definition: ValArray.inl:17
const std::array< T, Size > & data() const
Definition: ValArray.inl:27
ValArray< Size, T > & operator-=(const T &rhs)
Definition: ValArray.inl:57
constexpr size_t size() const
Definition: ValArray.inl:37
Matrix< Rows, Columns, T > operator/(const Matrix< Rows, Columns, T > &lhs, T rhs)
Matrix< Rows, Columns, T > operator*(const Matrix< Rows, Columns, T > &lhs, T rhs)