Skip to content

Commit

Permalink
Define subtraction via addition and division via multiplication
Browse files Browse the repository at this point in the history
  • Loading branch information
skitov committed Aug 31, 2022
1 parent 3c1a021 commit 07408b1
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions src/r4/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,23 +435,7 @@ template <class T, size_t S> class vector : public std::array<T, S>{
* @return Reference to this vector object.
*/
template <size_t SS> vector& operator-=(const vector<T, SS>& vec)noexcept{
if constexpr (SS >= S){
for(size_t i = 0; i != S; ++i){
this->operator[](i) -= vec[i];
}
}else if constexpr (S < 4 || SS >= 4){
static_assert(SS < S, "");
for(size_t i = 0; i != SS; ++i){
this->operator[](i) -= vec[i];
}
}else{
static_assert(SS < 4, "");
static_assert(S >= 4, "");
for(size_t i = 0; i != SS; ++i){
this->operator[](i) -= vec[i];
}
this->operator[](3) -= T(1);
}
(*this) += -vec;
return *this;
}

Expand All @@ -472,9 +456,7 @@ template <class T, size_t S> class vector : public std::array<T, S>{
* @return Reference to this vector object.
*/
vector& operator-=(T number)noexcept{
for(size_t i = 0; i != S; ++i){
this->operator[](i) -= number;
}
(*this) += -number;
return *this;
}

Expand Down Expand Up @@ -547,9 +529,7 @@ template <class T, size_t S> class vector : public std::array<T, S>{
*/
vector& operator/=(T num)noexcept{
ASSERT_INFO(num != 0, "vector::operator/=(): division by 0")
for(auto& c : *this){
c /= num;
}
(*this) *= T(1)/num;
return *this;
}

Expand Down

0 comments on commit 07408b1

Please sign in to comment.