Don't get confused with the wrong overload when passed a Vec.

This commit is contained in:
Michele Santullo 2015-08-14 12:56:40 +02:00
parent b2095603d1
commit 9ea9743e95
3 changed files with 25 additions and 8 deletions

View file

@ -161,10 +161,10 @@ namespace vwr {
template <typename V2>
typename std::enable_if<is_vec<V2>::value, V2>::type& cast ( void );
template <typename V2> VecBase& operator+= ( const VecBase<V2>& parOther );
template <typename V2> VecBase& operator-= ( const VecBase<V2>& parOther );
template <typename V2> VecBase& operator*= ( const VecBase<V2>& parOther );
template <typename V2> VecBase& operator/= ( const VecBase<V2>& parOther );
template <typename V2> VecBase& operator+= ( const Vec<V2>& parOther );
template <typename V2> VecBase& operator-= ( const Vec<V2>& parOther );
template <typename V2> VecBase& operator*= ( const Vec<V2>& parOther );
template <typename V2> VecBase& operator/= ( const Vec<V2>& parOther );
template <typename T> VecBase& operator+= ( const T& parOther );
template <typename T> VecBase& operator-= ( const T& parOther );
template <typename T> VecBase& operator*= ( const T& parOther );

View file

@ -97,7 +97,7 @@ namespace vwr {
template <typename V>
template <typename V2>
VecBase<V>& VecBase<V>::operator+= (const VecBase<V2>& parOther) {
VecBase<V>& VecBase<V>::operator+= (const Vec<V2>& parOther) {
static_assert(static_cast<int>(VectorWrapperInfo<V>::dimensions) == static_cast<int>(VectorWrapperInfo<V2>::dimensions), "Dimensions mismatch");
for (int z = 0; z < VectorWrapperInfo<V>::dimensions; ++z) {
(*this)[z] += parOther[z];
@ -106,7 +106,7 @@ namespace vwr {
}
template <typename V>
template <typename V2>
VecBase<V>& VecBase<V>::operator-= (const VecBase<V2>& parOther) {
VecBase<V>& VecBase<V>::operator-= (const Vec<V2>& parOther) {
static_assert(static_cast<int>(VectorWrapperInfo<V>::dimensions) == static_cast<int>(VectorWrapperInfo<V2>::dimensions), "Dimensions mismatch");
for (int z = 0; z < VectorWrapperInfo<V>::dimensions; ++z) {
(*this)[z] -= parOther[z];
@ -115,7 +115,7 @@ namespace vwr {
}
template <typename V>
template <typename V2>
VecBase<V>& VecBase<V>::operator*= (const VecBase<V2>& parOther) {
VecBase<V>& VecBase<V>::operator*= (const Vec<V2>& parOther) {
static_assert(static_cast<int>(VectorWrapperInfo<V>::dimensions) == static_cast<int>(VectorWrapperInfo<V2>::dimensions), "Dimensions mismatch");
for (int z = 0; z < VectorWrapperInfo<V>::dimensions; ++z) {
(*this)[z] *= parOther[z];
@ -124,7 +124,7 @@ namespace vwr {
}
template <typename V>
template <typename V2>
VecBase<V>& VecBase<V>::operator/= (const VecBase<V2>& parOther) {
VecBase<V>& VecBase<V>::operator/= (const Vec<V2>& parOther) {
static_assert(static_cast<int>(VectorWrapperInfo<V>::dimensions) == static_cast<int>(VectorWrapperInfo<V2>::dimensions), "Dimensions mismatch");
for (int z = 0; z < VectorWrapperInfo<V>::dimensions; ++z) {
(*this)[z] /= parOther[z];

View file

@ -3,8 +3,13 @@
TEST(misc, vector) {
typedef dk::Vector<2> coords2;
typedef dk::Vector<3> coords3;
typedef dk::Vector<8> coords8;
EXPECT_EQ(coords2::dimensions, 2);
EXPECT_EQ(coords3::dimensions, 3);
EXPECT_EQ(coords8::dimensions, 8);
{
const coords2 small(5, 6);
EXPECT_EQ(small.x(), 5);
@ -39,4 +44,16 @@ TEST(misc, vector) {
EXPECT_LT(small, big);
}
{
coords3 vec(1, 2, 3);
vec += coords3(3, 2, 1);
EXPECT_EQ(vec, coords3(4));
vec *= 3;
EXPECT_EQ(vec, coords3(12));
vec = coords3(2, 4, 8) / 2;
EXPECT_EQ(vec, coords3(1, 2, 4));
}
}