No need for a conversion overload. Conversion constructor should cast whatever it's assigning.
179 lines
6.1 KiB
C++
179 lines
6.1 KiB
C++
namespace cloonel {
|
|
///-------------------------------------------------------------------------
|
|
///-------------------------------------------------------------------------
|
|
template <typename T, uint32_t S>
|
|
Vector<T, S>::Vector (T parValue) :
|
|
m_mem {parValue}
|
|
{
|
|
}
|
|
|
|
///-------------------------------------------------------------------------
|
|
///-------------------------------------------------------------------------
|
|
template <typename T, uint32_t S>
|
|
template <typename U>
|
|
Vector<T, S>::Vector (const Vector<U, S>& parOther) {
|
|
for (uint32_t z = 0; z < S; ++z) {
|
|
m_mem[z] = static_cast<T>(parOther.m_mem[z]);
|
|
}
|
|
}
|
|
|
|
///-------------------------------------------------------------------------
|
|
///-------------------------------------------------------------------------
|
|
template <typename T, uint32_t S>
|
|
template <typename U>
|
|
const Vector<T, S>& Vector<T, S>::operator+= (const Vector<U, S>& parOther) {
|
|
for (uint32_t z = 0; z < S; ++z) {
|
|
m_mem[z] += parOther.m_mem[z];
|
|
}
|
|
return *this;
|
|
}
|
|
template <typename T, uint32_t S>
|
|
template <typename U>
|
|
const Vector<T, S>& Vector<T, S>::operator-= (const Vector<U, S>& parOther) {
|
|
for (uint32_t z = 0; z < S; ++z) {
|
|
m_mem[z] -= parOther.m_mem[z];
|
|
}
|
|
return *this;
|
|
}
|
|
template <typename T, uint32_t S>
|
|
template <typename U>
|
|
const Vector<T, S>& Vector<T, S>::operator*= (const Vector<U, S>& parOther) {
|
|
for (uint32_t z = 0; z < S; ++z) {
|
|
m_mem[z] *= parOther.m_mem[z];
|
|
}
|
|
return *this;
|
|
}
|
|
template <typename T, uint32_t S>
|
|
template <typename U>
|
|
const Vector<T, S>& Vector<T, S>::operator/= (const Vector<U, S>& parOther) {
|
|
for (uint32_t z = 0; z < S; ++z) {
|
|
m_mem[z] /= parOther.m_mem[z];
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
///-------------------------------------------------------------------------
|
|
///-------------------------------------------------------------------------
|
|
template <typename T, uint32_t S>
|
|
template <typename U>
|
|
const Vector<T, S>& Vector<T, S>::operator+= (U parOther) {
|
|
for (uint32_t z = 0; z < S; ++z) {
|
|
m_mem[z] += parOther;
|
|
}
|
|
return *this;
|
|
}
|
|
template <typename T, uint32_t S>
|
|
template <typename U>
|
|
const Vector<T, S>& Vector<T, S>::operator-= (U parOther) {
|
|
for (uint32_t z = 0; z < S; ++z) {
|
|
m_mem[z] -= parOther;
|
|
}
|
|
return *this;
|
|
}
|
|
template <typename T, uint32_t S>
|
|
template <typename U>
|
|
const Vector<T, S>& Vector<T, S>::operator*= (U parOther) {
|
|
for (uint32_t z = 0; z < S; ++z) {
|
|
m_mem[z] *= parOther;
|
|
}
|
|
return *this;
|
|
}
|
|
template <typename T, uint32_t S>
|
|
template <typename U>
|
|
const Vector<T, S>& Vector<T, S>::operator/= (U parOther) {
|
|
for (uint32_t z = 0; z < S; ++z) {
|
|
m_mem[z] /= parOther;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
///-------------------------------------------------------------------------
|
|
///-------------------------------------------------------------------------
|
|
template <typename T, typename U, uint32_t S>
|
|
inline
|
|
Vector<typename std::common_type<T, U>::type, S> operator+ (const Vector<T, S>& parA, const Vector<U, S>& parB) {
|
|
typedef typename std::common_type<T, U>::type RetType;
|
|
Vector<RetType, S> retVal(parA);
|
|
parA += parB;
|
|
return retVal;
|
|
}
|
|
template <typename T, typename U, uint32_t S>
|
|
inline
|
|
Vector<typename std::common_type<T, U>::type, S> operator- (const Vector<T, S>& parA, const Vector<U, S>& parB) {
|
|
typedef typename std::common_type<T, U>::type RetType;
|
|
Vector<RetType, S> retVal(parA);
|
|
parA -= parB;
|
|
return retVal;
|
|
}
|
|
template <typename T, typename U, uint32_t S>
|
|
inline
|
|
Vector<typename std::common_type<T, U>::type, S> operator* (const Vector<T, S>& parA, const Vector<U, S>& parB) {
|
|
typedef typename std::common_type<T, U>::type RetType;
|
|
Vector<RetType, S> retVal(parA);
|
|
parA *= parB;
|
|
return retVal;
|
|
}
|
|
template <typename T, typename U, uint32_t S>
|
|
inline
|
|
Vector<typename std::common_type<T, U>::type, S> operator/ (const Vector<T, S>& parA, const Vector<U, S>& parB) {
|
|
typedef typename std::common_type<T, U>::type RetType;
|
|
Vector<RetType, S> retVal(parA);
|
|
parA /= parB;
|
|
return retVal;
|
|
}
|
|
|
|
///-------------------------------------------------------------------------
|
|
///-------------------------------------------------------------------------
|
|
template <typename T, typename U, uint32_t S>
|
|
Vector<typename std::common_type<T, U>::type, S> operator+ (T parA, const Vector<U, S>& parB) {
|
|
return parB + parA;
|
|
}
|
|
template <typename T, typename U, uint32_t S>
|
|
Vector<typename std::common_type<T, U>::type, S> operator- (T parA, const Vector<U, S>& parB) {
|
|
return Vector<T, S>(parA) - parB;
|
|
}
|
|
template <typename T, typename U, uint32_t S>
|
|
Vector<typename std::common_type<T, U>::type, S> operator* (T parA, const Vector<U, S>& parB) {
|
|
return parB * parA;
|
|
}
|
|
template <typename T, typename U, uint32_t S>
|
|
Vector<typename std::common_type<T, U>::type, S> operator/ (T parA, const Vector<U, S>& parB) {
|
|
return Vector<T, S>(parA) / parB;
|
|
}
|
|
template <typename T, typename U, uint32_t S>
|
|
Vector<typename std::common_type<T, U>::type, S> operator+ (const Vector<T, S>& parA, U parB) {
|
|
typedef typename std::common_type<T, U>::type RetType;
|
|
Vector<RetType, S> retVal;
|
|
for (uint32_t z = 0; z < S; ++z) {
|
|
retVal[z] = parA[z] + parB;
|
|
}
|
|
return retVal;
|
|
}
|
|
template <typename T, typename U, uint32_t S>
|
|
Vector<typename std::common_type<T, U>::type, S> operator- (const Vector<T, S>& parA, U parB) {
|
|
typedef typename std::common_type<T, U>::type RetType;
|
|
Vector<RetType, S> retVal;
|
|
for (uint32_t z = 0; z < S; ++z) {
|
|
retVal[z] = parA[z] - parB;
|
|
}
|
|
return retVal;
|
|
}
|
|
template <typename T, typename U, uint32_t S>
|
|
Vector<typename std::common_type<T, U>::type, S> operator* (const Vector<T, S>& parA, U parB) {
|
|
typedef typename std::common_type<T, U>::type RetType;
|
|
Vector<RetType, S> retVal;
|
|
for (uint32_t z = 0; z < S; ++z) {
|
|
retVal[z] = parA[z] * parB;
|
|
}
|
|
return retVal;
|
|
}
|
|
template <typename T, typename U, uint32_t S>
|
|
Vector<typename std::common_type<T, U>::type, S> operator/ (const Vector<T, S>& parA, U parB) {
|
|
typedef typename std::common_type<T, U>::type RetType;
|
|
Vector<RetType, S> retVal;
|
|
for (uint32_t z = 0; z < S; ++z) {
|
|
retVal[z] = parA[z] / parB;
|
|
}
|
|
return retVal;
|
|
}
|
|
} //namespace cloonel
|