add extra templates

v1
Brett 2023-04-21 21:35:11 -04:00
parent 4b0226929b
commit 2d8e410a5c
1 changed files with 25 additions and 23 deletions

View File

@ -39,12 +39,14 @@ namespace blt {
elements[i] = *(args.begin() + i); elements[i] = *(args.begin() + i);
} }
explicit vec(const T elem[size]) { explicit vec(const T elem[], uint32_t v_size) {
for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < v_size; i++)
elements[i] = elem[i]; elements[i] = elem[i];
} }
vec(const vec<T, size>& copy): vec(copy.elements) {} vec(const vec<T, size>& copy): vec(copy.elements, size) {}
template<typename _T, uint32_t _size>
vec(const vec<_T, _size>& copy): vec(copy.elements, size) {}
vec& operator=(const vec<T, size>& copy) { vec& operator=(const vec<T, size>& copy) {
if (&copy == this) if (&copy == this)
@ -175,82 +177,82 @@ namespace blt {
template<typename T, uint32_t size> template<typename T, uint32_t size>
inline constexpr vec<T, size> operator+(const vec<T, size>& left, const vec<T, size>& right) { inline constexpr vec<T, size> operator+(const vec<T, size>& left, const vec<T, size>& right) {
T initializer[size]; vec<T, size> initializer{};
for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++)
initializer[i] = left[i] + right[i]; initializer[i] = left[i] + right[i];
return vec<T, size>{initializer}; return initializer;
} }
template<typename T, uint32_t size> template<typename T, uint32_t size>
inline constexpr vec<T, size> operator-(const vec<T, size>& left, const vec<T, size>& right) { inline constexpr vec<T, size> operator-(const vec<T, size>& left, const vec<T, size>& right) {
T initializer[size]; vec<T, size> initializer{};
for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++)
initializer[i] = left[i] - right[i]; initializer[i] = left[i] - right[i];
return vec<T, size>{initializer}; return initializer;
} }
template<typename T, uint32_t size> template<typename T, uint32_t size>
inline constexpr vec<T, size> operator+(const vec<T, size>& left, T f) { inline constexpr vec<T, size> operator+(const vec<T, size>& left, T f) {
T initializer[size]; vec<T, size> initializer{};
for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++)
initializer[i] = left[i] + f; initializer[i] = left[i] + f;
return vec<T, size>{initializer}; return initializer;
} }
template<typename T, uint32_t size> template<typename T, uint32_t size>
inline constexpr vec<T, size> operator-(const vec<T, size>& left, T f) { inline constexpr vec<T, size> operator-(const vec<T, size>& left, T f) {
T initializer[size]; vec<T, size> initializer{};
for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++)
initializer[i] = left[i] + f; initializer[i] = left[i] + f;
return vec<T, size>{initializer}; return initializer;
} }
template<typename T, uint32_t size> template<typename T, uint32_t size>
inline constexpr vec<T, size> operator+(T f, const vec<T, size>& right) { inline constexpr vec<T, size> operator+(T f, const vec<T, size>& right) {
T initializer[size]; vec<T, size> initializer{};
for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++)
initializer[i] = f + right[i]; initializer[i] = f + right[i];
return vec<T, size>{initializer}; return initializer;
} }
template<typename T, uint32_t size> template<typename T, uint32_t size>
inline constexpr vec<T, size> operator-(T f, const vec<T, size>& right) { inline constexpr vec<T, size> operator-(T f, const vec<T, size>& right) {
T initializer[size]; vec<T, size> initializer{};
for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++)
initializer[i] = f - right[i]; initializer[i] = f - right[i];
return vec<T, size>{initializer}; return initializer;
} }
template<typename T, uint32_t size> template<typename T, uint32_t size>
inline constexpr vec<T, size> operator*(const vec<T, size>& left, const vec<T, size>& right) { inline constexpr vec<T, size> operator*(const vec<T, size>& left, const vec<T, size>& right) {
T initializer[size]; vec<T, size> initializer{};
for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++)
initializer[i] = left[i] * right[i]; initializer[i] = left[i] * right[i];
return vec<T, size>{initializer}; return initializer;
} }
template<typename T, uint32_t size> template<typename T, uint32_t size>
inline constexpr vec<T, size> operator*(const vec<T, size>& left, T f) { inline constexpr vec<T, size> operator*(const vec<T, size>& left, T f) {
T initializer[size]; vec<T, size> initializer{};
for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++)
initializer[i] = left[i] * f; initializer[i] = left[i] * f;
return vec<T, size>{initializer}; return initializer;
} }
template<typename T, uint32_t size> template<typename T, uint32_t size>
inline constexpr vec<T, size> operator*(T f, const vec<T, size>& right) { inline constexpr vec<T, size> operator*(T f, const vec<T, size>& right) {
T initializer[size]; vec<T, size> initializer{};
for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++)
initializer[i] = f * right[i]; initializer[i] = f * right[i];
return vec<T, size>{initializer}; return initializer;
} }
template<typename T, uint32_t size> template<typename T, uint32_t size>
inline constexpr vec<T, size> operator/(const vec<T, size>& left, T f) { inline constexpr vec<T, size> operator/(const vec<T, size>& left, T f) {
T initializer[size]; vec<T, size> initializer{};
for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++)
initializer[i] = left[i] / f; initializer[i] = left[i] / f;
return vec<T, size>{initializer}; return initializer;
} }
template<typename T, uint32_t size> template<typename T, uint32_t size>