Browse Source

Math: constexpr implementation for "filling" Vector constructor.

Also removed constexpr alternatives to it in Vector2, Vector3 and
Vector4 as they are now not needed.
pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
0f938003df
  1. 10
      src/Math/Vector.h
  2. 2
      src/Math/Vector2.h
  3. 2
      src/Math/Vector3.h
  4. 2
      src/Math/Vector4.h

10
src/Math/Vector.h

@ -43,6 +43,8 @@ namespace Implementation {
template<std::size_t ...sequence> struct GenerateSequence<0, sequence...> {
typedef Sequence<sequence...> Type;
};
template<class T> inline constexpr T repeat(T value, std::size_t) { return value; }
}
#endif
@ -145,11 +147,8 @@ template<std::size_t size, class T> class Vector {
#ifdef DOXYGEN_GENERATING_OUTPUT
inline explicit Vector(T value);
#else
template<class U, class V = typename std::enable_if<std::is_same<T, U>::value && size != 1, T>::type> inline explicit Vector(U value) {
template<class U, class V = typename std::enable_if<std::is_same<T, U>::value && size != 1, T>::type> inline constexpr explicit Vector(U value): Vector(typename Implementation::GenerateSequence<size>::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<std::size_t size, class T> class Vector {
/* Implementation for Vector<size, T>::Vector(const Vector<size, U>&) */
template<class U, std::size_t ...sequence> inline constexpr explicit Vector(Implementation::Sequence<sequence...>, const Vector<sizeof...(sequence), U>& vector): _data{T(vector.data()[sequence])...} {}
/* Implementation for Vector<size, T>::Vector(U) */
template<std::size_t ...sequence> inline constexpr explicit Vector(Implementation::Sequence<sequence...>, T value): _data{Implementation::repeat(value, sequence)...} {}
T _data[size];
};

2
src/Math/Vector2.h

@ -75,7 +75,7 @@ template<class T> 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

2
src/Math/Vector3.h

@ -108,7 +108,7 @@ template<class T> 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

2
src/Math/Vector4.h

@ -38,7 +38,7 @@ template<class T> 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

Loading…
Cancel
Save