mirror of
https://github.com/g-truc/glm.git
synced 2024-11-22 17:04:35 +00:00
Improved constexpr support
This commit is contained in:
parent
178314a67d
commit
472f2c13b7
@ -61,14 +61,14 @@ namespace glm
|
||||
// -- Component accesses --
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER T & vec<1, T, Q>::operator[](typename vec<1, T, Q>::length_type i)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & vec<1, T, Q>::operator[](typename vec<1, T, Q>::length_type i)
|
||||
{
|
||||
assert(i >= 0 && i < this->length());
|
||||
return (&x)[i];
|
||||
}
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER T const& vec<1, T, Q>::operator[](typename vec<1, T, Q>::length_type i) const
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& vec<1, T, Q>::operator[](typename vec<1, T, Q>::length_type i) const
|
||||
{
|
||||
assert(i >= 0 && i < this->length());
|
||||
return (&x)[i];
|
||||
|
@ -60,7 +60,7 @@ namespace glm
|
||||
typedef length_t length_type;
|
||||
GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 2;}
|
||||
|
||||
GLM_FUNC_DECL T& operator[](length_type i);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR T& operator[](length_type i);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR T const& operator[](length_type i) const;
|
||||
|
||||
// -- Implicit basic constructors --
|
||||
@ -114,10 +114,10 @@ namespace glm
|
||||
|
||||
// -- Unary arithmetic operators --
|
||||
|
||||
GLM_FUNC_DECL vec<2, T, Q> & operator=(vec const& v) GLM_DEFAULT;
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> & operator=(vec const& v) GLM_DEFAULT;
|
||||
|
||||
template<typename U>
|
||||
GLM_FUNC_DECL vec<2, T, Q> & operator=(vec<2, U, Q> const& v);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> & operator=(vec<2, U, Q> const& v);
|
||||
template<typename U>
|
||||
GLM_FUNC_DECL vec<2, T, Q> & operator+=(U scalar);
|
||||
template<typename U>
|
||||
@ -193,27 +193,27 @@ namespace glm
|
||||
// -- Unary operators --
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<2, T, Q> operator+(vec<2, T, Q> const& v);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v);
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<2, T, Q> operator-(vec<2, T, Q> const& v);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator-(vec<2, T, Q> const& v);
|
||||
|
||||
// -- Binary operators --
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<2, T, Q> operator+(vec<2, T, Q> const& v, T scalar);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v, T scalar);
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2);
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<2, T, Q> operator+(T scalar, vec<2, T, Q> const& v);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(T scalar, vec<2, T, Q> const& v);
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<2, T, Q> operator+(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2);
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2);
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_DECL vec<2, T, Q> operator-(vec<2, T, Q> const& v, T scalar);
|
||||
|
@ -102,7 +102,7 @@ namespace glm
|
||||
// -- Component accesses --
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER T & vec<2, T, Q>::operator[](typename vec<2, T, Q>::length_type i)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & vec<2, T, Q>::operator[](typename vec<2, T, Q>::length_type i)
|
||||
{
|
||||
assert(i >= 0 && i < this->length());
|
||||
return (&x)[i];
|
||||
@ -119,7 +119,7 @@ namespace glm
|
||||
|
||||
# if GLM_USE_DEFAULTED_FUNCTIONS == GLM_DISABLE
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<2, T, Q> & vec<2, T, Q>::operator=(vec<2, T, Q> const& v)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> & vec<2, T, Q>::operator=(vec<2, T, Q> const& v)
|
||||
{
|
||||
this->x = v.x;
|
||||
this->y = v.y;
|
||||
@ -129,7 +129,7 @@ namespace glm
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
template<typename U>
|
||||
GLM_FUNC_QUALIFIER vec<2, T, Q> & vec<2, T, Q>::operator=(vec<2, U, Q> const& v)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> & vec<2, T, Q>::operator=(vec<2, U, Q> const& v)
|
||||
{
|
||||
this->x = static_cast<T>(v.x);
|
||||
this->y = static_cast<T>(v.y);
|
||||
@ -445,13 +445,13 @@ namespace glm
|
||||
// -- Unary arithmetic operators --
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<2, T, Q> operator+(vec<2, T, Q> const& v)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<2, T, Q> operator-(vec<2, T, Q> const& v)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> operator-(vec<2, T, Q> const& v)
|
||||
{
|
||||
return vec<2, T, Q>(
|
||||
-v.x,
|
||||
@ -461,7 +461,7 @@ namespace glm
|
||||
// -- Binary arithmetic operators --
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<2, T, Q> operator+(vec<2, T, Q> const& v, T scalar)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v, T scalar)
|
||||
{
|
||||
return vec<2, T, Q>(
|
||||
v.x + scalar,
|
||||
@ -469,7 +469,7 @@ namespace glm
|
||||
}
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2)
|
||||
{
|
||||
return vec<2, T, Q>(
|
||||
v1.x + v2.x,
|
||||
@ -477,7 +477,7 @@ namespace glm
|
||||
}
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<2, T, Q> operator+(T scalar, vec<2, T, Q> const& v)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> operator+(T scalar, vec<2, T, Q> const& v)
|
||||
{
|
||||
return vec<2, T, Q>(
|
||||
scalar + v.x,
|
||||
@ -485,7 +485,7 @@ namespace glm
|
||||
}
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<2, T, Q> operator+(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> operator+(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2)
|
||||
{
|
||||
return vec<2, T, Q>(
|
||||
v1.x + v2.x,
|
||||
@ -493,7 +493,7 @@ namespace glm
|
||||
}
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2)
|
||||
{
|
||||
return vec<2, T, Q>(
|
||||
v1.x + v2.x,
|
||||
|
@ -61,7 +61,7 @@ namespace glm
|
||||
typedef length_t length_type;
|
||||
GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 3;}
|
||||
|
||||
GLM_FUNC_DECL T & operator[](length_type i);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR T & operator[](length_type i);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR T const& operator[](length_type i) const;
|
||||
|
||||
// -- Implicit basic constructors --
|
||||
|
@ -164,7 +164,7 @@ namespace glm
|
||||
// -- Component accesses --
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER T & vec<3, T, Q>::operator[](typename vec<3, T, Q>::length_type i)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & vec<3, T, Q>::operator[](typename vec<3, T, Q>::length_type i)
|
||||
{
|
||||
assert(i >= 0 && i < this->length());
|
||||
return (&x)[i];
|
||||
|
@ -62,7 +62,7 @@ namespace glm
|
||||
typedef length_t length_type;
|
||||
GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 4;}
|
||||
|
||||
GLM_FUNC_DECL T & operator[](length_type i);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR T & operator[](length_type i);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR T const& operator[](length_type i) const;
|
||||
|
||||
// -- Implicit basic constructors --
|
||||
|
@ -503,7 +503,7 @@ namespace detail
|
||||
// -- Component accesses --
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER T& vec<4, T, Q>::operator[](typename vec<4, T, Q>::length_type i)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T& vec<4, T, Q>::operator[](typename vec<4, T, Q>::length_type i)
|
||||
{
|
||||
assert(i >= 0 && i < this->length());
|
||||
return (&x)[i];
|
||||
|
@ -78,8 +78,8 @@ namespace glm
|
||||
typedef length_t length_type;
|
||||
GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 1;}
|
||||
|
||||
GLM_FUNC_DECL T & operator[](length_type i);
|
||||
GLM_FUNC_DECL T const& operator[](length_type i) const;
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR T & operator[](length_type i);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR T const& operator[](length_type i) const;
|
||||
|
||||
// -- Implicit basic constructors --
|
||||
|
||||
|
@ -56,7 +56,7 @@ namespace glm
|
||||
/// Return the count of components of a quaternion
|
||||
GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 4;}
|
||||
|
||||
GLM_FUNC_DECL T & operator[](length_type i);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR T & operator[](length_type i);
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR T const& operator[](length_type i) const;
|
||||
|
||||
// -- Implicit basic constructors --
|
||||
|
@ -75,7 +75,7 @@ namespace detail
|
||||
// -- Component accesses --
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER T & tquat<T, Q>::operator[](typename tquat<T, Q>::length_type i)
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & tquat<T, Q>::operator[](typename tquat<T, Q>::length_type i)
|
||||
{
|
||||
assert(i >= 0 && i < this->length());
|
||||
return (&x)[i];
|
||||
|
@ -31,6 +31,8 @@ static int test_vec1()
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec1 A(1);
|
||||
static_assert(A[0] == 1, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec1(1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec1::length() == 1, "GLM: Failed constexpr");
|
||||
}
|
||||
@ -85,6 +87,8 @@ static int test_vec2()
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 A(1);
|
||||
static_assert(A[0] == 1, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec2(1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec2(1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec2(1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr");
|
||||
@ -100,6 +104,13 @@ static int test_vec2()
|
||||
static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 A(1);
|
||||
constexpr glm::ivec2 B = A + 1;
|
||||
constexpr glm::ivec2 C(3);
|
||||
static_assert(A + B == C, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
@ -161,6 +172,8 @@ static int test_vec3()
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 const A(1);
|
||||
static_assert(A[0] == 1, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec3(1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec3(1.0f, -1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec3(1.0f, -1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr");
|
||||
@ -215,6 +228,8 @@ static int test_vec4()
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec4 A(1);
|
||||
static_assert(A[0] == 1, "GLM: Failed constexpr");
|
||||
static_assert(glm::ivec4(1).x > 0, "GLM: Failed constexpr");
|
||||
static_assert(glm::ivec4(1.0f, -1.0f, -1.0f, 1.0f).x > 0, "GLM: Failed constexpr");
|
||||
static_assert(glm::ivec4(1.0f, -1.0f, -1.0f, 1.0f).y < 0, "GLM: Failed constexpr");
|
||||
@ -244,6 +259,7 @@ static int test_quat()
|
||||
|
||||
glm::quat constexpr Q = glm::identity<glm::quat>();
|
||||
static_assert(Q.x - glm::quat(1.0f, glm::vec3(0.0f)).x <= glm::epsilon<float>(), "GLM: Failed constexpr");
|
||||
static_assert(Q[0] == 0, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
return Error;
|
||||
|
Loading…
Reference in New Issue
Block a user