diff --git a/src/Magnum/Color.h b/src/Magnum/Color.h index 66ce2c3b6..6ff9c2976 100644 --- a/src/Magnum/Color.h +++ b/src/Magnum/Color.h @@ -254,7 +254,7 @@ template class BasicColor3: public Math::Vector3 { * * All components are set to zero. */ - constexpr /*implicit*/ BasicColor3() {} + constexpr /*implicit*/ BasicColor3(Math::ZeroInitT = Math::ZeroInit): Math::Vector3{Math::ZeroInit} {} /** * @brief Gray constructor diff --git a/src/Magnum/Math/Algorithms/Svd.h b/src/Magnum/Math/Algorithms/Svd.h index 824edc3f5..5dfa4e93f 100644 --- a/src/Magnum/Math/Algorithms/Svd.h +++ b/src/Magnum/Math/Algorithms/Svd.h @@ -102,7 +102,7 @@ template std::tuple T(0), "Tol too small"); constexpr std::size_t maxIterations = 50; - Matrix v(Matrix::Zero); + Matrix v{ZeroInit}; Vector e, q; /* Householder's reduction to bidiagonal form */ @@ -270,7 +270,7 @@ template std::tuple= maxIterations-1) { Corrade::Utility::Error() << "Magnum::Math::Algorithms::svd(): no convergence"; - return std::make_tuple(RectangularMatrix(), Vector(), Matrix(Matrix::Zero)); + return std::make_tuple(RectangularMatrix{}, Vector{}, Matrix{ZeroInit}); } /* Shift from bottom 2x2 minor */ diff --git a/src/Magnum/Math/Algorithms/Test/SvdTest.cpp b/src/Magnum/Math/Algorithms/Test/SvdTest.cpp index e17de15bf..6cc826c27 100644 --- a/src/Magnum/Math/Algorithms/Test/SvdTest.cpp +++ b/src/Magnum/Math/Algorithms/Test/SvdTest.cpp @@ -88,8 +88,8 @@ void SvdTest::testDouble() { CORRADE_COMPARE(u2*w2*v.transposed(), ad); /* Test that V is unitary */ - CORRADE_COMPARE(v*v.transposed(), Matrix5d(Matrix5d::Identity)); - CORRADE_COMPARE(v.transposed()*v, Matrix5d(Matrix5d::Identity)); + CORRADE_COMPARE(v*v.transposed(), Matrix5d{IdentityInit}); + CORRADE_COMPARE(v.transposed()*v, Matrix5d{IdentityInit}); /* Test W */ CORRADE_COMPARE(w, expectedd); @@ -110,8 +110,8 @@ void SvdTest::testFloat() { CORRADE_VERIFY(Math::abs((u2*w2*v.transposed()-af).toVector()).max() < 1.0e-5f); /* Test that V is unitary */ - CORRADE_COMPARE(v*v.transposed(), Matrix5f(Matrix5f::Identity)); - CORRADE_COMPARE(v.transposed()*v, Matrix5f(Matrix5f::Identity)); + CORRADE_COMPARE(v*v.transposed(), Matrix5f{IdentityInit}); + CORRADE_COMPARE(v.transposed()*v, Matrix5f{IdentityInit}); /* Test W (single precision is not enough, test for similarity) */ CORRADE_VERIFY(Math::abs(w-expectedf).max() < 1.0e-5f); diff --git a/src/Magnum/Math/Angle.h b/src/Magnum/Math/Angle.h index 79ea78849..6a4c83092 100644 --- a/src/Magnum/Math/Angle.h +++ b/src/Magnum/Math/Angle.h @@ -123,8 +123,8 @@ std::sin(Float(Rad(b)); // required explicit conversion hints to user */ template class Deg: public Unit { public: - /** @brief Default constructor */ - constexpr /*implicit*/ Deg() {} + /** @brief Construct zero angle */ + constexpr /*implicit*/ Deg(ZeroInitT = ZeroInit): Unit{ZeroInit} {} /** @brief Explicit constructor from unitless type */ constexpr explicit Deg(T value): Unit(value) {} @@ -182,7 +182,7 @@ See @ref Deg for more information. template class Rad: public Unit { public: /** @brief Default constructor */ - constexpr /*implicit*/ Rad() {} + constexpr /*implicit*/ Rad(ZeroInitT = ZeroInit): Unit{ZeroInit} {} /** @brief Construct from unitless type */ constexpr explicit Rad(T value): Unit(value) {} diff --git a/src/Magnum/Math/BoolVector.h b/src/Magnum/Math/BoolVector.h index 8b1edefa5..3e4c951f8 100644 --- a/src/Magnum/Math/BoolVector.h +++ b/src/Magnum/Math/BoolVector.h @@ -33,6 +33,7 @@ #include #include "Magnum/Types.h" +#include "Magnum/Math/Tags.h" namespace Magnum { namespace Math { @@ -70,7 +71,7 @@ template class BoolVector { static const std::size_t DataSize = (size-1)/8+1; /**< @brief Vector storage size */ /** @brief Construct zero-filled boolean vector */ - constexpr BoolVector(): _data() {} + constexpr /*implicit*/ BoolVector(ZeroInitT = ZeroInit): _data{} {} /** * @brief Construct boolean vector from segment values diff --git a/src/Magnum/Math/Complex.h b/src/Magnum/Math/Complex.h index b299edbee..19ee98fbc 100644 --- a/src/Magnum/Math/Complex.h +++ b/src/Magnum/Math/Complex.h @@ -140,7 +140,7 @@ template class Complex { * c = 1 + i0 * @f] */ - constexpr /*implicit*/ Complex(): _real(T(1)), _imaginary(T(0)) {} + constexpr /*implicit*/ Complex(IdentityInitT = IdentityInit): _real(T(1)), _imaginary(T(0)) {} /** * @brief Construct complex number from real and imaginary part diff --git a/src/Magnum/Math/DualComplex.h b/src/Magnum/Math/DualComplex.h index 0b6c90b66..7ffb80b28 100644 --- a/src/Magnum/Math/DualComplex.h +++ b/src/Magnum/Math/DualComplex.h @@ -104,9 +104,9 @@ template class DualComplex: public Dual> { * @f] */ #ifdef DOXYGEN_GENERATING_OUTPUT - constexpr /*implicit*/ DualComplex(); + constexpr /*implicit*/ DualComplex(IdentityInitT = IdentityInit); #else - constexpr /*implicit*/ DualComplex(): Dual>({}, {T(0), T(0)}) {} + constexpr /*implicit*/ DualComplex(IdentityInitT = IdentityInit): Dual>({}, {T(0), T(0)}) {} #endif /** diff --git a/src/Magnum/Math/DualQuaternion.h b/src/Magnum/Math/DualQuaternion.h index a9415d67b..09cf6a4d1 100644 --- a/src/Magnum/Math/DualQuaternion.h +++ b/src/Magnum/Math/DualQuaternion.h @@ -110,9 +110,9 @@ template class DualQuaternion: public Dual> { * @f] */ #ifdef DOXYGEN_GENERATING_OUTPUT - constexpr /*implicit*/ DualQuaternion(); + constexpr /*implicit*/ DualQuaternion(IdentityInitT = IdentityInit); #else - constexpr /*implicit*/ DualQuaternion(): Dual>({}, {{}, T(0)}) {} + constexpr /*implicit*/ DualQuaternion(IdentityInitT = IdentityInit): Dual>({}, {{}, T(0)}) {} #endif /** diff --git a/src/Magnum/Math/Matrix.h b/src/Magnum/Math/Matrix.h index 380df95e4..be5c8fe37 100644 --- a/src/Magnum/Math/Matrix.h +++ b/src/Magnum/Math/Matrix.h @@ -51,27 +51,40 @@ template class Matrix: public RectangularMatrix(typename Implementation::GenerateSequence::Type(), Vector(value)) {} + constexpr /*implicit*/ Matrix(IdentityInitT = IdentityInit, T value = T(1)): RectangularMatrix(typename Implementation::GenerateSequence::Type(), Vector(value)) {} + + /** @copydoc RectangularMatrix::RectangularMatrix(ZeroInitT) */ + constexpr explicit Matrix(ZeroInitT): RectangularMatrix{ZeroInit} {} /** * @brief Matrix from column vectors @@ -291,7 +304,7 @@ template bool Matrix::isOrthogonal() const { } template Matrix Matrix::ij(const std::size_t skipCol, const std::size_t skipRow) const { - Matrix out(Matrix::Zero); + Matrix out{ZeroInit}; for(std::size_t col = 0; col != size-1; ++col) for(std::size_t row = 0; row != size-1; ++row) @@ -302,7 +315,7 @@ template Matrix Matrix::ij(const } template Matrix Matrix::inverted() const { - Matrix out(Zero); + Matrix out{ZeroInit}; const T _determinant = determinant(); diff --git a/src/Magnum/Math/Matrix3.h b/src/Magnum/Math/Matrix3.h index cf9d1ad35..52cc74fb1 100644 --- a/src/Magnum/Math/Matrix3.h +++ b/src/Magnum/Math/Matrix3.h @@ -153,17 +153,16 @@ template class Matrix3: public Matrix3x3 { { translation, T(1)}}; } - /** @copydoc Matrix::Matrix(ZeroType) */ - constexpr explicit Matrix3(typename Matrix3x3::ZeroType): Matrix3x3(Matrix3x3::Zero) {} - /** * @brief Default constructor * - * Creates identity matrix. You can also explicitly call this - * constructor with `Matrix3 m(Matrix3::Identity);`. Optional - * parameter @p value allows you to specify value on diagonal. + * Creates identity matrix. @p value allows you to specify value on + * diagonal. */ - constexpr /*implicit*/ Matrix3(typename Matrix3x3::IdentityType = (Matrix3x3::Identity), T value = T(1)): Matrix3x3(Matrix3x3::Identity, value) {} + constexpr /*implicit*/ Matrix3(IdentityInitT = IdentityInit, T value = T{1}): Matrix3x3{IdentityInit, value} {} + + /** @copydoc Matrix::Matrix(ZeroInitT) */ + constexpr explicit Matrix3(ZeroInitT): Matrix3x3{ZeroInit} {} /** @brief Matrix from column vectors */ constexpr /*implicit*/ Matrix3(const Vector3& first, const Vector3& second, const Vector3& third): Matrix3x3(first, second, third) {} diff --git a/src/Magnum/Math/Matrix4.h b/src/Magnum/Math/Matrix4.h index d38d34eea..ca60d272a 100644 --- a/src/Magnum/Math/Matrix4.h +++ b/src/Magnum/Math/Matrix4.h @@ -249,17 +249,16 @@ template class Matrix4: public Matrix4x4 { { translation, T(1)}}; } - /** @copydoc Matrix::Matrix(ZeroType) */ - constexpr explicit Matrix4(typename Matrix4x4::ZeroType): Matrix4x4(Matrix4x4::Zero) {} - /** * @brief Default constructor * - * Creates identity matrix. You can also explicitly call this - * constructor with `Matrix4 m(Matrix4::Identity);`. Optional - * parameter @p value allows you to specify value on diagonal. + * Creates identity matrix. @p value allows you to specify value on + * diagonal. */ - constexpr /*implicit*/ Matrix4(typename Matrix4x4::IdentityType = (Matrix4x4::Identity), T value = T(1)): Matrix4x4(Matrix4x4::Identity, value) {} + constexpr /*implicit*/ Matrix4(IdentityInitT = IdentityInit, T value = T{1}): Matrix4x4{IdentityInit, value} {} + + /** @copydoc Matrix::Matrix(ZeroInitT) */ + constexpr explicit Matrix4(ZeroInitT): Matrix4x4{ZeroInit} {} /** @brief Matrix from column vectors */ constexpr /*implicit*/ Matrix4(const Vector4& first, const Vector4& second, const Vector4& third, const Vector4& fourth): Matrix4x4(first, second, third, fourth) {} diff --git a/src/Magnum/Math/Quaternion.h b/src/Magnum/Math/Quaternion.h index a7274e744..07d35787c 100644 --- a/src/Magnum/Math/Quaternion.h +++ b/src/Magnum/Math/Quaternion.h @@ -197,7 +197,7 @@ template class Quaternion { * q = [\boldsymbol 0, 1] * @f] */ - constexpr /*implicit*/ Quaternion(): _scalar(T(1)) {} + constexpr /*implicit*/ Quaternion(IdentityInitT = IdentityInit): _vector{T(0)}, _scalar{T(1)} {} /** * @brief Construct quaternion from vector and scalar diff --git a/src/Magnum/Math/Range.h b/src/Magnum/Math/Range.h index 3821f3719..13396346d 100644 --- a/src/Magnum/Math/Range.h +++ b/src/Magnum/Math/Range.h @@ -75,10 +75,10 @@ template class Range { * * Construct zero-size range positioned at origin. */ - constexpr Range(): _min{}, _max{} {} + constexpr /*implicit*/ Range(ZeroInitT = ZeroInit): _min{ZeroInit}, _max{ZeroInit} {} /** @brief Construct range from minimal and maximal coordinates */ - constexpr Range(const VectorType& min, const VectorType& max): _min(min), _max(max) {} + constexpr /*implicit*/ Range(const VectorType& min, const VectorType& max): _min{min}, _max{max} {} /** @brief Copy constructor */ constexpr Range(const Range&) = default; @@ -218,8 +218,8 @@ See @ref Range for more information. */ template class Range2D: public Range<2, T> { public: - /** @copydoc Range() */ - constexpr /*implicit*/ Range2D() {} + /** @copydoc Range(ZeroInitT) */ + constexpr /*implicit*/ Range2D(ZeroInitT = ZeroInit): Range<2, T>{ZeroInit} {} /** @copydoc Range(const VectorType&, const VectorType&) */ constexpr /*implicit*/ Range2D(const Vector2& min, const Vector2& max): Range<2, T>(min, max) {} @@ -329,8 +329,8 @@ See @ref Range for more information. */ template class Range3D: public Range<3, T> { public: - /** @copydoc Range() */ - constexpr /*implicit*/ Range3D() {} + /** @copydoc Range(ZeroInitT) */ + constexpr /*implicit*/ Range3D(ZeroInitT = ZeroInit): Range<3, T>{ZeroInit} {} /** @copydoc Range(const VectorType&, const VectorType&) */ constexpr /*implicit*/ Range3D(const Vector3& min, const Vector3& max): Range<3, T>(min, max) {} diff --git a/src/Magnum/Math/RectangularMatrix.h b/src/Magnum/Math/RectangularMatrix.h index da933abe2..e2f731023 100644 --- a/src/Magnum/Math/RectangularMatrix.h +++ b/src/Magnum/Math/RectangularMatrix.h @@ -106,7 +106,7 @@ template class RectangularMatrix { } /** @brief Construct zero-filled matrix */ - constexpr /*implicit*/ RectangularMatrix() {} + constexpr /*implicit*/ RectangularMatrix(ZeroInitT = ZeroInit): RectangularMatrix{typename Implementation::GenerateSequence::Type{}, ZeroInit} {} /** * @brief Construct matrix from column vectors @@ -361,6 +361,9 @@ template class RectangularMatrix { /* Implementation for RectangularMatrix::RectangularMatrix(const RectangularMatrix&) */ template constexpr explicit RectangularMatrix(Implementation::Sequence, const RectangularMatrix& matrix): _data{Vector(matrix[sequence])...} {} + /* Implementation for RectangularMatrix::RectangularMatrix(ZeroInitT) */ + template constexpr explicit RectangularMatrix(Implementation::Sequence, U): _data{Vector{(static_cast(sequence), U{})}...} {} + template constexpr Vector diagonalInternal(Implementation::Sequence) const; Vector _data[cols]; diff --git a/src/Magnum/Math/Test/AngleTest.cpp b/src/Magnum/Math/Test/AngleTest.cpp index 06d477d90..50a8708a2 100644 --- a/src/Magnum/Math/Test/AngleTest.cpp +++ b/src/Magnum/Math/Test/AngleTest.cpp @@ -59,14 +59,20 @@ AngleTest::AngleTest() { void AngleTest::construct() { /* Default constructor */ - constexpr Deg m; - CORRADE_COMPARE(Float(m), 0.0f); + constexpr Deg m1; + constexpr Deg m2{ZeroInit}; + CORRADE_COMPARE(Float(m1), 0.0f); + CORRADE_COMPARE(Float(m2), 0.0f); #ifndef MAGNUM_TARGET_GLES - constexpr Degd a; - CORRADE_COMPARE(Double(a), 0.0); + constexpr Radd a1; + constexpr Radd a2{ZeroInit}; + CORRADE_COMPARE(Double(a1), 0.0); + CORRADE_COMPARE(Double(a2), 0.0); #else - constexpr Deg a; - CORRADE_COMPARE(Float(a), 0.0f); + constexpr Rad a1; + constexpr Rad a2{ZeroInit}; + CORRADE_COMPARE(Float(a1), 0.0f); + CORRADE_COMPARE(Float(a2), 0.0f); #endif /* Value constructor */ diff --git a/src/Magnum/Math/Test/BoolVectorTest.cpp b/src/Magnum/Math/Test/BoolVectorTest.cpp index e835968d4..03933ff43 100644 --- a/src/Magnum/Math/Test/BoolVectorTest.cpp +++ b/src/Magnum/Math/Test/BoolVectorTest.cpp @@ -85,7 +85,9 @@ void BoolVectorTest::construct() { void BoolVectorTest::constructDefault() { constexpr BoolVector19 a; + constexpr BoolVector19 b{ZeroInit}; CORRADE_COMPARE(a, BoolVector19(0x00, 0x00, 0x00)); + CORRADE_COMPARE(b, BoolVector19(0x00, 0x00, 0x00)); } void BoolVectorTest::constructOneValue() { diff --git a/src/Magnum/Math/Test/ComplexTest.cpp b/src/Magnum/Math/Test/ComplexTest.cpp index 7009a725b..995e7ecbe 100644 --- a/src/Magnum/Math/Test/ComplexTest.cpp +++ b/src/Magnum/Math/Test/ComplexTest.cpp @@ -58,7 +58,7 @@ struct ComplexTest: Corrade::TestSuite::Tester { explicit ComplexTest(); void construct(); - void constructDefault(); + void constructIdentity(); void constructFromVector(); void constructCopy(); void convert(); @@ -90,7 +90,7 @@ struct ComplexTest: Corrade::TestSuite::Tester { ComplexTest::ComplexTest() { addTests({&ComplexTest::construct, - &ComplexTest::constructDefault, + &ComplexTest::constructIdentity, &ComplexTest::constructFromVector, &ComplexTest::constructCopy, &ComplexTest::convert, @@ -137,10 +137,13 @@ void ComplexTest::construct() { CORRADE_COMPARE(c, -3.7f); } -void ComplexTest::constructDefault() { +void ComplexTest::constructIdentity() { constexpr Complex a; + constexpr Complex b{IdentityInit}; CORRADE_COMPARE(a, Complex(1.0f, 0.0f)); + CORRADE_COMPARE(b, Complex(1.0f, 0.0f)); CORRADE_COMPARE(a.length(), 1.0f); + CORRADE_COMPARE(b.length(), 1.0f); } void ComplexTest::constructFromVector() { diff --git a/src/Magnum/Math/Test/DualComplexTest.cpp b/src/Magnum/Math/Test/DualComplexTest.cpp index b2a9917e5..8ecb51464 100644 --- a/src/Magnum/Math/Test/DualComplexTest.cpp +++ b/src/Magnum/Math/Test/DualComplexTest.cpp @@ -58,7 +58,7 @@ struct DualComplexTest: Corrade::TestSuite::Tester { explicit DualComplexTest(); void construct(); - void constructDefault(); + void constructIdentity(); void constructFromVector(); void constructCopy(); void convert(); @@ -96,7 +96,7 @@ typedef Math::Vector2 Vector2; DualComplexTest::DualComplexTest() { addTests({&DualComplexTest::construct, - &DualComplexTest::constructDefault, + &DualComplexTest::constructIdentity, &DualComplexTest::constructFromVector, &DualComplexTest::constructCopy, &DualComplexTest::convert, @@ -137,10 +137,13 @@ void DualComplexTest::construct() { CORRADE_COMPARE(d, DualComplex({-1.0f, 2.5f}, {0.0f, 0.0f})); } -void DualComplexTest::constructDefault() { +void DualComplexTest::constructIdentity() { constexpr DualComplex a; + constexpr DualComplex b{IdentityInit}; CORRADE_COMPARE(a, DualComplex({1.0f, 0.0f}, {0.0f, 0.0f})); + CORRADE_COMPARE(b, DualComplex({1.0f, 0.0f}, {0.0f, 0.0f})); CORRADE_COMPARE(a.length(), 1.0f); + CORRADE_COMPARE(b.length(), 1.0f); } void DualComplexTest::constructFromVector() { diff --git a/src/Magnum/Math/Test/DualQuaternionTest.cpp b/src/Magnum/Math/Test/DualQuaternionTest.cpp index 4f4c2892b..556a82e19 100644 --- a/src/Magnum/Math/Test/DualQuaternionTest.cpp +++ b/src/Magnum/Math/Test/DualQuaternionTest.cpp @@ -60,7 +60,7 @@ struct DualQuaternionTest: Corrade::TestSuite::Tester { explicit DualQuaternionTest(); void construct(); - void constructDefault(); + void constructIdentity(); void constructFromVector(); void constructCopy(); void convert(); @@ -97,7 +97,7 @@ typedef Math::Vector3 Vector3; DualQuaternionTest::DualQuaternionTest() { addTests({&DualQuaternionTest::construct, - &DualQuaternionTest::constructDefault, + &DualQuaternionTest::constructIdentity, &DualQuaternionTest::constructFromVector, &DualQuaternionTest::constructCopy, &DualQuaternionTest::convert, @@ -138,10 +138,13 @@ void DualQuaternionTest::construct() { CORRADE_COMPARE(d, DualQuaternion({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f})); } -void DualQuaternionTest::constructDefault() { +void DualQuaternionTest::constructIdentity() { constexpr DualQuaternion a; + constexpr DualQuaternion b{IdentityInit}; CORRADE_COMPARE(a, DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f})); + CORRADE_COMPARE(b, DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f})); CORRADE_COMPARE(a.length(), 1.0f); + CORRADE_COMPARE(b.length(), 1.0f); } void DualQuaternionTest::constructFromVector() { diff --git a/src/Magnum/Math/Test/Matrix3Test.cpp b/src/Magnum/Math/Test/Matrix3Test.cpp index a6233b476..f12313f45 100644 --- a/src/Magnum/Math/Test/Matrix3Test.cpp +++ b/src/Magnum/Math/Test/Matrix3Test.cpp @@ -138,8 +138,8 @@ void Matrix3Test::construct() { void Matrix3Test::constructIdentity() { constexpr Matrix3 identity; - constexpr Matrix3 identity2(Matrix3::Identity); - constexpr Matrix3 identity3(Matrix3::Identity, 4.0f); + constexpr Matrix3 identity2{IdentityInit}; + constexpr Matrix3 identity3{IdentityInit, 4.0f}; Matrix3 identityExpected({1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, @@ -155,7 +155,7 @@ void Matrix3Test::constructIdentity() { } void Matrix3Test::constructZero() { - constexpr Matrix3 a(Matrix3::Zero); + constexpr Matrix3 a{ZeroInit}; CORRADE_COMPARE(a, Matrix3({0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f})); diff --git a/src/Magnum/Math/Test/Matrix4Test.cpp b/src/Magnum/Math/Test/Matrix4Test.cpp index 3d855e6d5..66a300d84 100644 --- a/src/Magnum/Math/Test/Matrix4Test.cpp +++ b/src/Magnum/Math/Test/Matrix4Test.cpp @@ -159,8 +159,8 @@ void Matrix4Test::construct() { void Matrix4Test::constructIdentity() { constexpr Matrix4 identity; - constexpr Matrix4 identity2(Matrix4::Identity); - constexpr Matrix4 identity3(Matrix4::Identity, 4.0f); + constexpr Matrix4 identity2{IdentityInit}; + constexpr Matrix4 identity3{IdentityInit, 4.0f}; Matrix4 identityExpected({1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, @@ -179,7 +179,7 @@ void Matrix4Test::constructIdentity() { void Matrix4Test::constructZero() { /* Zero constructor */ - constexpr Matrix4 a(Matrix4::Zero); + constexpr Matrix4 a{ZeroInit}; CORRADE_COMPARE(a, Matrix4({0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 0.0f}, diff --git a/src/Magnum/Math/Test/MatrixTest.cpp b/src/Magnum/Math/Test/MatrixTest.cpp index 5553b6d6f..1f2946e40 100644 --- a/src/Magnum/Math/Test/MatrixTest.cpp +++ b/src/Magnum/Math/Test/MatrixTest.cpp @@ -125,8 +125,8 @@ void MatrixTest::construct() { void MatrixTest::constructIdentity() { constexpr Matrix4x4 identity; - constexpr Matrix4x4 identity2(Matrix4x4::Identity); - constexpr Matrix4x4 identity3(Matrix4x4::Identity, 4.0f); + constexpr Matrix4x4 identity2{IdentityInit}; + constexpr Matrix4x4 identity3{IdentityInit, 4.0f}; Matrix4x4 identityExpected(Vector4(1.0f, 0.0f, 0.0f, 0.0f), Vector4(0.0f, 1.0f, 0.0f, 0.0f), @@ -144,7 +144,7 @@ void MatrixTest::constructIdentity() { } void MatrixTest::constructZero() { - constexpr Matrix4x4 a(Matrix4x4::Zero); + constexpr Matrix4x4 a{ZeroInit}; CORRADE_COMPARE(a, Matrix4x4(Vector4(0.0f, 0.0f, 0.0f, 0.0f), Vector4(0.0f, 0.0f, 0.0f, 0.0f), Vector4(0.0f, 0.0f, 0.0f, 0.0f), diff --git a/src/Magnum/Math/Test/QuaternionTest.cpp b/src/Magnum/Math/Test/QuaternionTest.cpp index 45ac12d17..e25d4f02c 100644 --- a/src/Magnum/Math/Test/QuaternionTest.cpp +++ b/src/Magnum/Math/Test/QuaternionTest.cpp @@ -58,7 +58,7 @@ struct QuaternionTest: Corrade::TestSuite::Tester { explicit QuaternionTest(); void construct(); - void constructDefault(); + void constructIdentity(); void constructFromVector(); void constructCopy(); void convert(); @@ -101,7 +101,7 @@ typedef Math::Vector4 Vector4; QuaternionTest::QuaternionTest() { addTests({&QuaternionTest::construct, - &QuaternionTest::constructDefault, + &QuaternionTest::constructIdentity, &QuaternionTest::constructFromVector, &QuaternionTest::constructCopy, &QuaternionTest::convert, @@ -144,10 +144,13 @@ void QuaternionTest::construct() { CORRADE_COMPARE(c, -4.0f); } -void QuaternionTest::constructDefault() { +void QuaternionTest::constructIdentity() { constexpr Quaternion a; + constexpr Quaternion b{IdentityInit}; CORRADE_COMPARE(a, Quaternion({0.0f, 0.0f, 0.0f}, 1.0f)); + CORRADE_COMPARE(b, Quaternion({0.0f, 0.0f, 0.0f}, 1.0f)); CORRADE_COMPARE(a.length(), 1.0f); + CORRADE_COMPARE(b.length(), 1.0f); } void QuaternionTest::constructFromVector() { diff --git a/src/Magnum/Math/Test/RangeTest.cpp b/src/Magnum/Math/Test/RangeTest.cpp index 537247799..b2863dfe5 100644 --- a/src/Magnum/Math/Test/RangeTest.cpp +++ b/src/Magnum/Math/Test/RangeTest.cpp @@ -173,13 +173,19 @@ void RangeTest::construct() { } void RangeTest::constructDefault() { - constexpr Range1Di a; - constexpr Range2Di b; - constexpr Range3Di c; - - CORRADE_COMPARE(a, Range1Di(0, 0)); - CORRADE_COMPARE(b, Range2Di({0, 0}, {0, 0})); - CORRADE_COMPARE(c, Range3Di({0, 0, 0}, {0, 0, 0})); + constexpr Range1Di a1; + constexpr Range2Di b1; + constexpr Range3Di c1; + constexpr Range1Di a2{ZeroInit}; + constexpr Range2Di b2{ZeroInit}; + constexpr Range3Di c2{ZeroInit}; + + CORRADE_COMPARE(a1, Range1Di(0, 0)); + CORRADE_COMPARE(a2, Range1Di(0, 0)); + CORRADE_COMPARE(b1, Range2Di({0, 0}, {0, 0})); + CORRADE_COMPARE(b2, Range2Di({0, 0}, {0, 0})); + CORRADE_COMPARE(c1, Range3Di({0, 0, 0}, {0, 0, 0})); + CORRADE_COMPARE(c2, Range3Di({0, 0, 0}, {0, 0, 0})); } void RangeTest::constructFromSize() { diff --git a/src/Magnum/Math/Test/RectangularMatrixTest.cpp b/src/Magnum/Math/Test/RectangularMatrixTest.cpp index 75f84b404..faa0e141c 100644 --- a/src/Magnum/Math/Test/RectangularMatrixTest.cpp +++ b/src/Magnum/Math/Test/RectangularMatrixTest.cpp @@ -148,10 +148,15 @@ void RectangularMatrixTest::construct() { void RectangularMatrixTest::constructDefault() { constexpr Matrix4x3 a; + constexpr Matrix4x3 b{ZeroInit}; CORRADE_COMPARE(a, Matrix4x3(Vector3(0.0f, 0.0f, 0.0f), Vector3(0.0f, 0.0f, 0.0f), Vector3(0.0f, 0.0f, 0.0f), Vector3(0.0f, 0.0f, 0.0f))); + CORRADE_COMPARE(b, Matrix4x3(Vector3(0.0f, 0.0f, 0.0f), + Vector3(0.0f, 0.0f, 0.0f), + Vector3(0.0f, 0.0f, 0.0f), + Vector3(0.0f, 0.0f, 0.0f))); } void RectangularMatrixTest::constructConversion() { diff --git a/src/Magnum/Math/Test/Vector2Test.cpp b/src/Magnum/Math/Test/Vector2Test.cpp index 5fbf11cff..4ba013675 100644 --- a/src/Magnum/Math/Test/Vector2Test.cpp +++ b/src/Magnum/Math/Test/Vector2Test.cpp @@ -106,7 +106,9 @@ void Vector2Test::construct() { void Vector2Test::constructDefault() { constexpr Vector2 a; + constexpr Vector2 b{ZeroInit}; CORRADE_COMPARE(a, Vector2(0.0f, 0.0f)); + CORRADE_COMPARE(b, Vector2(0.0f, 0.0f)); } void Vector2Test::constructOneValue() { diff --git a/src/Magnum/Math/Test/Vector3Test.cpp b/src/Magnum/Math/Test/Vector3Test.cpp index f3af3b62a..37fd2c972 100644 --- a/src/Magnum/Math/Test/Vector3Test.cpp +++ b/src/Magnum/Math/Test/Vector3Test.cpp @@ -104,7 +104,9 @@ void Vector3Test::construct() { void Vector3Test::constructDefault() { constexpr Vector3 a; + constexpr Vector3 b{ZeroInit}; CORRADE_COMPARE(a, Vector3(0.0f, 0.0f, 0.0f)); + CORRADE_COMPARE(b, Vector3(0.0f, 0.0f, 0.0f)); } void Vector3Test::constructOneValue() { diff --git a/src/Magnum/Math/Test/Vector4Test.cpp b/src/Magnum/Math/Test/Vector4Test.cpp index 1f56703f8..ecee35c5a 100644 --- a/src/Magnum/Math/Test/Vector4Test.cpp +++ b/src/Magnum/Math/Test/Vector4Test.cpp @@ -113,7 +113,9 @@ void Vector4Test::constructPad() { void Vector4Test::constructDefault() { constexpr Vector4 a; + constexpr Vector4 b{ZeroInit}; CORRADE_COMPARE(a, Vector4(0.0f, 0.0f, 0.0f, 0.0f)); + CORRADE_COMPARE(b, Vector4(0.0f, 0.0f, 0.0f, 0.0f)); } void Vector4Test::constructOneValue() { diff --git a/src/Magnum/Math/Test/VectorTest.cpp b/src/Magnum/Math/Test/VectorTest.cpp index bdd1cf5f6..1f6266dae 100644 --- a/src/Magnum/Math/Test/VectorTest.cpp +++ b/src/Magnum/Math/Test/VectorTest.cpp @@ -187,7 +187,9 @@ void VectorTest::constructPad() { void VectorTest::constructDefault() { constexpr Vector4 a; + constexpr Vector4 b{ZeroInit}; CORRADE_COMPARE(a, Vector4(0.0f, 0.0f, 0.0f, 0.0f)); + CORRADE_COMPARE(b, Vector4(0.0f, 0.0f, 0.0f, 0.0f)); } void VectorTest::constructOneValue() { diff --git a/src/Magnum/Math/Unit.h b/src/Magnum/Math/Unit.h index fbfe3a43b..5e679eade 100644 --- a/src/Magnum/Math/Unit.h +++ b/src/Magnum/Math/Unit.h @@ -30,6 +30,7 @@ */ #include "Magnum/Math/TypeTraits.h" +#include "Magnum/Math/Tags.h" namespace Magnum { namespace Math { @@ -45,8 +46,8 @@ template class Derived, class T> class Unit { public: typedef T Type; /**< @brief Underlying data type */ - /** @brief Default constructor */ - constexpr /*implicit*/ Unit(): _value(T(0)) {} + /** @brief Construct zero value */ + constexpr /*implicit*/ Unit(ZeroInitT = ZeroInit): _value(T(0)) {} /** @brief Explicit conversion from unitless type */ constexpr explicit Unit(T value): _value(value) {} diff --git a/src/Magnum/Math/Vector.h b/src/Magnum/Math/Vector.h index 2a4c9f695..18e75e256 100644 --- a/src/Magnum/Math/Vector.h +++ b/src/Magnum/Math/Vector.h @@ -146,7 +146,7 @@ template class Vector { * \boldsymbol v = \boldsymbol 0 * @f] */ - constexpr /*implicit*/ Vector(): _data() {} + constexpr /*implicit*/ Vector(ZeroInitT = ZeroInit): _data{} {} /** @todo Creating Vector from combination of vector and scalar types */ diff --git a/src/Magnum/Math/Vector2.h b/src/Magnum/Math/Vector2.h index d73ccf29e..04c1c4673 100644 --- a/src/Magnum/Math/Vector2.h +++ b/src/Magnum/Math/Vector2.h @@ -111,8 +111,8 @@ template class Vector2: public Vector<2, T> { } #endif - /** @copydoc Vector::Vector() */ - constexpr /*implicit*/ Vector2() {} + /** @copydoc Vector::Vector(ZeroInitT) */ + constexpr /*implicit*/ Vector2(ZeroInitT = ZeroInit): Vector<2, T>{ZeroInit} {} /** @copydoc Vector::Vector(T) */ constexpr explicit Vector2(T value): Vector<2, T>(value) {} diff --git a/src/Magnum/Math/Vector3.h b/src/Magnum/Math/Vector3.h index 93277ac0d..2200498bb 100644 --- a/src/Magnum/Math/Vector3.h +++ b/src/Magnum/Math/Vector3.h @@ -133,8 +133,8 @@ template class Vector3: public Vector<3, T> { } #endif - /** @copydoc Vector::Vector() */ - constexpr /*implicit*/ Vector3() {} + /** @copydoc Vector::Vector(ZeroInitT) */ + constexpr /*implicit*/ Vector3(ZeroInitT = ZeroInit): Vector<3, T>{ZeroInit} {} /** @copydoc Vector::Vector(T) */ constexpr explicit Vector3(T value): Vector<3, T>(value) {} diff --git a/src/Magnum/Math/Vector4.h b/src/Magnum/Math/Vector4.h index cb958154b..1db87832a 100644 --- a/src/Magnum/Math/Vector4.h +++ b/src/Magnum/Math/Vector4.h @@ -59,8 +59,8 @@ template class Vector4: public Vector<4, T> { 3 < otherSize ? a[3] : w}; } - /** @copydoc Vector::Vector() */ - constexpr /*implicit*/ Vector4() {} + /** @copydoc Vector::Vector(ZeroInitT) */ + constexpr /*implicit*/ Vector4(ZeroInitT = ZeroInit): Vector<4, T>{ZeroInit} {} /** @copydoc Vector::Vector(T) */ constexpr explicit Vector4(T value): Vector<4, T>(value) {} diff --git a/src/Magnum/SceneGraph/Test/ObjectTest.cpp b/src/Magnum/SceneGraph/Test/ObjectTest.cpp index ef8935fca..d084482e9 100644 --- a/src/Magnum/SceneGraph/Test/ObjectTest.cpp +++ b/src/Magnum/SceneGraph/Test/ObjectTest.cpp @@ -371,16 +371,16 @@ void ObjectTest::setClean() { CORRADE_VERIFY(childThree->isDirty()); /* If the object itself is already clean, it shouldn't clean it again */ - childOne->cleanedAbsoluteTransformation = Matrix4(Matrix4::Zero); + childOne->cleanedAbsoluteTransformation = Matrix4{Math::ZeroInit}; CORRADE_VERIFY(!childOne->isDirty()); childOne->setClean(); - CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero)); + CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4{Math::ZeroInit}); /* If any object in the hierarchy is already clean, it shouldn't clean it again */ CORRADE_VERIFY(!childOne->isDirty()); CORRADE_VERIFY(childTwo->isDirty()); childTwo->setClean(); - CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero)); + CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4{Math::ZeroInit}); /* Remove object from tree => make it and its children dirty */ childThree->setClean(); @@ -441,16 +441,16 @@ void ObjectTest::setCleanListHierarchy() { CORRADE_COMPARE(childTwoFeature->cleanedAbsoluteTransformation, childTwo->absoluteTransformationMatrix()); /* If the object itself is already clean, it shouldn't clean it again */ - childOne->cleanedAbsoluteTransformation = Matrix4(Matrix4::Zero); + childOne->cleanedAbsoluteTransformation = Matrix4{Math::ZeroInit}; CORRADE_VERIFY(!childOne->isDirty()); Scene3D::setClean({*childOne}); - CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero)); + CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4{Math::ZeroInit}); /* If any object in the hierarchy is already clean, it shouldn't clean it again */ CORRADE_VERIFY(!childOne->isDirty()); childTwo->setDirty(); Scene3D::setClean({*childTwo}); - CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero)); + CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4{Math::ZeroInit}); } void ObjectTest::setCleanListBulk() { diff --git a/src/Magnum/Shapes/Box.h b/src/Magnum/Shapes/Box.h index d4e004bda..6cf57169c 100644 --- a/src/Magnum/Shapes/Box.h +++ b/src/Magnum/Shapes/Box.h @@ -56,7 +56,7 @@ template class MAGNUM_SHAPES_EXPORT Box { * * Creates zero-sized box positioned at origin. */ - constexpr /*implicit*/ Box(): _transformation(MatrixTypeFor::Zero) {} + constexpr /*implicit*/ Box(): _transformation{Math::ZeroInit} {} /** @brief Constructor */ constexpr /*implicit*/ Box(const MatrixTypeFor& transformation): _transformation(transformation) {} diff --git a/src/Magnum/Test/ColorTest.cpp b/src/Magnum/Test/ColorTest.cpp index 9a1bf9347..c9e30f681 100644 --- a/src/Magnum/Test/ColorTest.cpp +++ b/src/Magnum/Test/ColorTest.cpp @@ -104,8 +104,10 @@ void ColorTest::construct() { } void ColorTest::constructDefault() { - constexpr Vector3 a; - CORRADE_COMPARE(a, Color3(0.0f, 0.0f, 0.0f)); + constexpr Color3 a1; + constexpr Color3 a2{Math::ZeroInit}; + CORRADE_COMPARE(a1, Color3(0.0f, 0.0f, 0.0f)); + CORRADE_COMPARE(a2, Color3(0.0f, 0.0f, 0.0f)); constexpr Color4 b; constexpr Color4ub c;