Browse Source

GCC 4.6 compatibility: no delegating constructors.

Don't know why the corresponding conversion operator can't be constexpr.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
999b7d55c0
  1. 8
      src/Math/Test/VectorTest.cpp
  2. 7
      src/Math/Vector.h

8
src/Math/Test/VectorTest.cpp

@ -201,10 +201,18 @@ void VectorTest::convert() {
constexpr Vec3 a{1.5f, 2.0f, -3.5f};
constexpr Vector3 b(1.5f, 2.0f, -3.5f);
#ifndef CORRADE_GCC46_COMPATIBILITY
constexpr Vector3 c(a);
#else
Vector3 c(a); /* Not constexpr under GCC < 4.7 */
#endif
CORRADE_COMPARE(c, b);
#ifndef CORRADE_GCC46_COMPATIBILITY
constexpr Vec3 d(b);
#else
Vec3 d(b); /* Not constexpr under GCC < 4.7 */
#endif
CORRADE_COMPARE(d.x, a.x);
CORRADE_COMPARE(d.y, a.y);
CORRADE_COMPARE(d.z, a.z);

7
src/Math/Vector.h

@ -162,7 +162,13 @@ template<std::size_t size, class T> class Vector {
#endif
/** @brief Construct vector from external representation */
#ifndef CORRADE_GCC46_COMPATIBILITY
template<class U, class V = decltype(Implementation::VectorConverter<size, T, U>::from(std::declval<U>()))> inline constexpr explicit Vector(const U& other): Vector(Implementation::VectorConverter<size, T, U>::from(other)) {}
#else
template<class U, class V = decltype(Implementation::VectorConverter<size, T, U>::from(std::declval<U>()))> inline explicit Vector(const U& other) {
*this = Vector(Implementation::VectorConverter<size, T, U>::from(other));
}
#endif
/** @brief Copy constructor */
inline constexpr Vector(const Vector<size, T>&) = default;
@ -172,6 +178,7 @@ template<std::size_t size, class T> class Vector {
/** @brief Convert vector to external representation */
template<class U, class V = decltype(Implementation::VectorConverter<size, T, U>::to(std::declval<Vector<size, T>>()))> inline constexpr explicit operator U() const {
/** @bug Why this is not constexpr under GCC 4.6? */
return Implementation::VectorConverter<size, T, U>::to(*this);
}

Loading…
Cancel
Save