Browse Source

MSVC 2015 compatibility: Math conversion constructor constexpr issues.

Some could be worked around, but the rest is prevented by inability to
delegate constexpr constructors.
pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
d805e87f21
  1. 9
      src/Magnum/Math/Matrix.h
  2. 12
      src/Magnum/Math/RectangularMatrix.h
  3. 6
      src/Magnum/Math/Test/RangeTest.cpp
  4. 6
      src/Magnum/Math/Test/RectangularMatrixTest.cpp
  5. 6
      src/Magnum/Math/Test/VectorTest.cpp
  6. 7
      src/Magnum/Math/Vector.h
  7. 9
      src/Magnum/Math/Vector2.h
  8. 9
      src/Magnum/Math/Vector3.h
  9. 9
      src/Magnum/Math/Vector4.h

9
src/Magnum/Math/Matrix.h

@ -132,7 +132,14 @@ template<std::size_t size, class T> class Matrix: public RectangularMatrix<size,
* // integral == {{1, 2}, {-15, 7}} * // integral == {{1, 2}, {-15, 7}}
* @endcode * @endcode
*/ */
template<class U> constexpr explicit Matrix(const RectangularMatrix<size, size, U>& other): RectangularMatrix<size, size, T>(other) {} template<class U> constexpr explicit Matrix(const RectangularMatrix<size, size, U>& other):
#ifndef CORRADE_MSVC2015_COMPATIBILITY
RectangularMatrix<size, size, T>(other)
#else
/* Avoid using non-constexpr version */
RectangularMatrix<size, size, T>(typename Implementation::GenerateSequence<size>::Type(), other)
#endif
{}
/** @brief Construct matrix from external representation */ /** @brief Construct matrix from external representation */
template<class U, class V = decltype(Implementation::RectangularMatrixConverter<size, size, T, U>::from(std::declval<U>()))> constexpr explicit Matrix(const U& other): RectangularMatrix<size, size, T>(Implementation::RectangularMatrixConverter<size, size, T, U>::from(other)) {} template<class U, class V = decltype(Implementation::RectangularMatrixConverter<size, size, T, U>::from(std::declval<U>()))> constexpr explicit Matrix(const U& other): RectangularMatrix<size, size, T>(Implementation::RectangularMatrixConverter<size, size, T, U>::from(other)) {}

12
src/Magnum/Math/RectangularMatrix.h

@ -57,6 +57,11 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
template<std::size_t, std::size_t, class> friend class RectangularMatrix; template<std::size_t, std::size_t, class> friend class RectangularMatrix;
#ifdef CORRADE_MSVC2015_COMPATIBILITY
/* Delegating constexpr constructor workarounds */
friend class Matrix<cols, T>;
#endif
public: public:
typedef T Type; /**< @brief Underlying data type */ typedef T Type; /**< @brief Underlying data type */
@ -152,7 +157,12 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
* // integral == {1, 2, -15, 7} * // integral == {1, 2, -15, 7}
* @endcode * @endcode
*/ */
template<class U> constexpr explicit RectangularMatrix(const RectangularMatrix<cols, rows, U>& other): RectangularMatrix(typename Implementation::GenerateSequence<cols>::Type(), other) {} template<class U>
#ifndef CORRADE_MSVC2015_COMPATIBILITY
/* Can't use delegating constructors with constexpr -- https://connect.microsoft.com/VisualStudio/feedback/details/1579279/c-constexpr-does-not-work-with-delegating-constructors */
constexpr
#endif
explicit RectangularMatrix(const RectangularMatrix<cols, rows, U>& other): RectangularMatrix(typename Implementation::GenerateSequence<cols>::Type(), other) {}
/** @brief Construct matrix from external representation */ /** @brief Construct matrix from external representation */
template<class U, class V = decltype(Implementation::RectangularMatrixConverter<cols, rows, T, U>::from(std::declval<U>()))> constexpr explicit RectangularMatrix(const U& other): RectangularMatrix(Implementation::RectangularMatrixConverter<cols, rows, T, U>::from(other)) {} template<class U, class V = decltype(Implementation::RectangularMatrixConverter<cols, rows, T, U>::from(std::declval<U>()))> constexpr explicit RectangularMatrix(const U& other): RectangularMatrix(Implementation::RectangularMatrixConverter<cols, rows, T, U>::from(other)) {}

6
src/Magnum/Math/Test/RangeTest.cpp

@ -215,7 +215,11 @@ void RangeTest::constructConversion() {
constexpr Range2D b({1.3f, 2.7f}, {-15.0f, 7.0f}); constexpr Range2D b({1.3f, 2.7f}, {-15.0f, 7.0f});
constexpr Range3D c({1.3f, 2.7f, -1.5f}, {-15.0f, 7.0f, 0.3f}); constexpr Range3D c({1.3f, 2.7f, -1.5f}, {-15.0f, 7.0f, 0.3f});
constexpr Range1Di d(a); #ifndef CORRADE_MSVC2015_COMPATIBILITY
/* Can't use delegating constructors with constexpr -- https://connect.microsoft.com/VisualStudio/feedback/details/1579279/c-constexpr-does-not-work-with-delegating-constructors */
constexpr
#endif
Range1Di d(a);
CORRADE_COMPARE(d, Range1Di(1, -15)); CORRADE_COMPARE(d, Range1Di(1, -15));
constexpr Range2Di e(b); constexpr Range2Di e(b);

6
src/Magnum/Math/Test/RectangularMatrixTest.cpp

@ -174,7 +174,11 @@ void RectangularMatrixTest::constructNoInit() {
void RectangularMatrixTest::constructConversion() { void RectangularMatrixTest::constructConversion() {
constexpr Matrix2x2 a(Vector2( 1.3f, 2.7f), constexpr Matrix2x2 a(Vector2( 1.3f, 2.7f),
Vector2(-15.0f, 7.0f)); Vector2(-15.0f, 7.0f));
constexpr Matrix2x2i b(a); #ifndef CORRADE_MSVC2015_COMPATIBILITY
/* Can't use delegating constructors with constexpr -- https://connect.microsoft.com/VisualStudio/feedback/details/1579279/c-constexpr-does-not-work-with-delegating-constructors */
constexpr
#endif
Matrix2x2i b(a);
CORRADE_COMPARE(b, Matrix2x2i(Vector2i( 1, 2), CORRADE_COMPARE(b, Matrix2x2i(Vector2i( 1, 2),
Vector2i(-15, 7))); Vector2i(-15, 7)));

6
src/Magnum/Math/Test/VectorTest.cpp

@ -223,7 +223,11 @@ void VectorTest::constructOneComponent() {
void VectorTest::constructConversion() { void VectorTest::constructConversion() {
constexpr Vector4 a(1.3f, 2.7f, -15.0f, 7.0f); constexpr Vector4 a(1.3f, 2.7f, -15.0f, 7.0f);
constexpr Vector4i b(a); #ifndef CORRADE_MSVC2015_COMPATIBILITY
/* Can't use delegating constructors with constexpr -- https://connect.microsoft.com/VisualStudio/feedback/details/1579279/c-constexpr-does-not-work-with-delegating-constructors */
constexpr
#endif
Vector4i b(a);
CORRADE_COMPARE(b, Vector4i(1, 2, -15, 7)); CORRADE_COMPARE(b, Vector4i(1, 2, -15, 7));

7
src/Magnum/Math/Vector.h

@ -94,6 +94,13 @@ template<std::size_t size, class T> class Vector {
template<std::size_t, class> friend class Vector; template<std::size_t, class> friend class Vector;
#ifdef CORRADE_MSVC2015_COMPATIBILITY
/* Delegating constexpr constructor workarounds */
friend class Vector2<T>;
friend class Vector3<T>;
friend class Vector4<T>;
#endif
public: public:
typedef T Type; /**< @brief Underlying data type */ typedef T Type; /**< @brief Underlying data type */

9
src/Magnum/Math/Vector2.h

@ -149,7 +149,14 @@ template<class T> class Vector2: public Vector<2, T> {
constexpr /*implicit*/ Vector2(T x, T y): Vector<2, T>(x, y) {} constexpr /*implicit*/ Vector2(T x, T y): Vector<2, T>(x, y) {}
/** @copydoc Vector::Vector(const Vector<size, U>&) */ /** @copydoc Vector::Vector(const Vector<size, U>&) */
template<class U> constexpr explicit Vector2(const Vector<2, U>& other): Vector<2, T>(other) {} template<class U> constexpr explicit Vector2(const Vector<2, U>& other):
#ifndef CORRADE_MSVC2015_COMPATIBILITY
Vector<2, T>(other)
#else
/* Avoid using non-constexpr version */
Vector<2, T>(typename Implementation::GenerateSequence<2>::Type(), other)
#endif
{}
/** @brief Construct vector from external representation */ /** @brief Construct vector from external representation */
template<class U, class V = decltype(Implementation::VectorConverter<2, T, U>::from(std::declval<U>()))> constexpr explicit Vector2(const U& other): Vector<2, T>(Implementation::VectorConverter<2, T, U>::from(other)) {} template<class U, class V = decltype(Implementation::VectorConverter<2, T, U>::from(std::declval<U>()))> constexpr explicit Vector2(const U& other): Vector<2, T>(Implementation::VectorConverter<2, T, U>::from(other)) {}

9
src/Magnum/Math/Vector3.h

@ -180,7 +180,14 @@ template<class T> class Vector3: public Vector<3, T> {
constexpr /*implicit*/ Vector3(const Vector2<T>& xy, T z): Vector<3, T>(xy[0], xy[1], z) {} constexpr /*implicit*/ Vector3(const Vector2<T>& xy, T z): Vector<3, T>(xy[0], xy[1], z) {}
/** @copydoc Vector::Vector(const Vector<size, U>&) */ /** @copydoc Vector::Vector(const Vector<size, U>&) */
template<class U> constexpr explicit Vector3(const Vector<3, U>& other): Vector<3, T>(other) {} template<class U> constexpr explicit Vector3(const Vector<3, U>& other):
#ifndef CORRADE_MSVC2015_COMPATIBILITY
Vector<3, T>(other)
#else
/* Avoid using non-constexpr version */
Vector<3, T>(typename Implementation::GenerateSequence<3>::Type(), other)
#endif
{}
/** @brief Construct vector from external representation */ /** @brief Construct vector from external representation */
template<class U, class V = decltype(Implementation::VectorConverter<3, T, U>::from(std::declval<U>()))> constexpr explicit Vector3(const U& other): Vector<3, T>(Implementation::VectorConverter<3, T, U>::from(other)) {} template<class U, class V = decltype(Implementation::VectorConverter<3, T, U>::from(std::declval<U>()))> constexpr explicit Vector3(const U& other): Vector<3, T>(Implementation::VectorConverter<3, T, U>::from(other)) {}

9
src/Magnum/Math/Vector4.h

@ -106,7 +106,14 @@ template<class T> class Vector4: public Vector<4, T> {
constexpr /*implicit*/ Vector4(const Vector3<T>& xyz, T w): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {} constexpr /*implicit*/ Vector4(const Vector3<T>& xyz, T w): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {}
/** @copydoc Vector::Vector(const Vector<size, U>&) */ /** @copydoc Vector::Vector(const Vector<size, U>&) */
template<class U> constexpr explicit Vector4(const Vector<4, U>& other): Vector<4, T>(other) {} template<class U> constexpr explicit Vector4(const Vector<4, U>& other):
#ifndef CORRADE_MSVC2015_COMPATIBILITY
Vector<4, T>(other)
#else
/* Avoid using non-constexpr version */
Vector<4, T>(typename Implementation::GenerateSequence<4>::Type(), other)
#endif
{}
/** @brief Construct vector from external representation */ /** @brief Construct vector from external representation */
template<class U, class V = decltype(Implementation::VectorConverter<4, T, U>::from(std::declval<U>()))> constexpr explicit Vector4(const U& other): Vector<4, T>(Implementation::VectorConverter<4, T, U>::from(other)) {} template<class U, class V = decltype(Implementation::VectorConverter<4, T, U>::from(std::declval<U>()))> constexpr explicit Vector4(const U& other): Vector<4, T>(Implementation::VectorConverter<4, T, U>::from(other)) {}

Loading…
Cancel
Save