diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 4be582d1f..ee5b1c30b 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -43,6 +43,8 @@ namespace Implementation { template struct GenerateSequence<0, sequence...> { typedef Sequence Type; }; + + template inline constexpr T repeat(T value, std::size_t) { return value; } } #endif @@ -145,11 +147,8 @@ template class Vector { #ifdef DOXYGEN_GENERATING_OUTPUT inline explicit Vector(T value); #else - template::value && size != 1, T>::type> inline explicit Vector(U value) { + template::value && size != 1, T>::type> inline constexpr explicit Vector(U value): Vector(typename Implementation::GenerateSequence::Type(), value) {} #endif - for(std::size_t i = 0; i != size; ++i) - _data[i] = value; - } /** * @brief Construct vector from another of different type @@ -516,6 +515,9 @@ template class Vector { /* Implementation for Vector::Vector(const Vector&) */ template inline constexpr explicit Vector(Implementation::Sequence, const Vector& vector): _data{T(vector.data()[sequence])...} {} + /* Implementation for Vector::Vector(U) */ + template inline constexpr explicit Vector(Implementation::Sequence, T value): _data{Implementation::repeat(value, sequence)...} {} + T _data[size]; }; diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 0cf539a8c..2fa7116c2 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -75,7 +75,7 @@ template class Vector2: public Vector<2, T> { inline constexpr /*implicit*/ Vector2() {} /** @copydoc Vector::Vector(T) */ - inline constexpr explicit Vector2(T value): Vector<2, T>(value, value) {} + inline constexpr explicit Vector2(T value): Vector<2, T>(value) {} /** * @brief Constructor diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 5a7a2354d..a2ad90872 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -108,7 +108,7 @@ template class Vector3: public Vector<3, T> { inline constexpr /*implicit*/ Vector3() {} /** @copydoc Vector::Vector(T) */ - inline constexpr explicit Vector3(T value): Vector<3, T>(value, value, value) {} + inline constexpr explicit Vector3(T value): Vector<3, T>(value) {} /** * @brief Constructor diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 1c0963f5f..329a96d94 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -38,7 +38,7 @@ template class Vector4: public Vector<4, T> { inline constexpr /*implicit*/ Vector4() {} /** @copydoc Vector::Vector(T) */ - inline constexpr explicit Vector4(T value): Vector<4, T>(value, value, value, value) {} + inline constexpr explicit Vector4(T value): Vector<4, T>(value) {} /** * @brief Constructor