Added support of defaulted functions to *vec* types #366

This commit is contained in:
Christophe Riccio 2015-07-25 01:24:03 +02:00
parent 063c5c7367
commit f7751bfb06
14 changed files with 229 additions and 131 deletions

View File

@ -619,7 +619,8 @@
#else
# define GLM_HAS_DEFAULTED_FUNCTIONS (GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\
((GLM_COMPILER & GLM_COMPILER_GCC) && (GLM_COMPILER >= GLM_COMPILER_GCC44)) || \
((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC2013)))
((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC2013)) || \
((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_COMPILER >= GLM_COMPILER_INTEL12)))
#endif
// N2118
@ -923,6 +924,12 @@
# define GLM_RESTRICT_VAR
#endif//GLM_COMPILER
#if GLM_HAS_DEFAULTED_FUNCTIONS
# define GLM_DEFAULT = default
#else
# define GLM_DEFAULT
#endif
#if GLM_HAS_CONSTEXPR
# define GLM_CONSTEXPR constexpr
# define GLM_RELAXED_CONSTEXPR constexpr

View File

@ -112,8 +112,8 @@ namespace glm
//////////////////////////////////////
// Implicit basic constructors
GLM_FUNC_DECL tvec1();
GLM_FUNC_DECL tvec1(tvec1<T, P> const & v);
GLM_FUNC_DECL tvec1() GLM_DEFAULT;
GLM_FUNC_DECL tvec1(tvec1<T, P> const & v) GLM_DEFAULT;
template <precision Q>
GLM_FUNC_DECL tvec1(tvec1<T, Q> const & v);
@ -154,7 +154,7 @@ namespace glm
//////////////////////////////////////
// Unary arithmetic operators
GLM_FUNC_DECL tvec1<T, P> & operator=(tvec1<T, P> const & v);
GLM_FUNC_DECL tvec1<T, P> & operator=(tvec1<T, P> const & v) GLM_DEFAULT;
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator=(tvec1<U, P> const & v);

View File

@ -35,6 +35,7 @@ namespace glm
//////////////////////////////////////
// Implicit basic constructors
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec1<T, P>::tvec1()
# ifndef GLM_FORCE_NO_CTOR_INIT
@ -46,6 +47,7 @@ namespace glm
GLM_FUNC_QUALIFIER tvec1<T, P>::tvec1(tvec1<T, P> const & v)
: x(v.x)
{}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
template <precision Q>
@ -140,12 +142,14 @@ namespace glm
//////////////////////////////////////
// Unary arithmetic operators
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator=(tvec1<T, P> const & v)
{
this->x = v.x;
return *this;
}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
template <typename U>

View File

@ -113,8 +113,8 @@ namespace glm
//////////////////////////////////////
// Implicit basic constructors
GLM_FUNC_DECL tvec2();
GLM_FUNC_DECL tvec2(tvec2<T, P> const & v);
GLM_FUNC_DECL tvec2() GLM_DEFAULT;
GLM_FUNC_DECL tvec2(tvec2<T, P> const & v) GLM_DEFAULT;
template <precision Q>
GLM_FUNC_DECL tvec2(tvec2<T, Q> const & v);
@ -162,7 +162,7 @@ namespace glm
//////////////////////////////////////
// Unary arithmetic operators
GLM_FUNC_DECL tvec2<T, P>& operator=(tvec2<T, P> const & v);
GLM_FUNC_DECL tvec2<T, P>& operator=(tvec2<T, P> const & v) GLM_DEFAULT;
template <typename U>
GLM_FUNC_DECL tvec2<T, P>& operator=(tvec2<U, P> const & v);

View File

@ -28,40 +28,10 @@
namespace glm
{
#ifdef GLM_FORCE_SIZE_FUNC
template <typename T, precision P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR size_t tvec2<T, P>::size() const
{
return 2;
}
#else
template <typename T, precision P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t tvec2<T, P>::length() const
{
return 2;
}
#endif
//////////////////////////////////////
// Accesses
template <typename T, precision P>
GLM_FUNC_QUALIFIER T & tvec2<T, P>::operator[](length_t i)
{
assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
return (&x)[i];
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER T const & tvec2<T, P>::operator[](length_t i) const
{
assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
return (&x)[i];
}
//////////////////////////////////////
// Implicit basic constructors
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P>::tvec2()
# ifndef GLM_FORCE_NO_CTOR_INIT
@ -73,6 +43,7 @@ namespace glm
GLM_FUNC_QUALIFIER tvec2<T, P>::tvec2(tvec2<T, P> const & v)
: x(v.x), y(v.y)
{}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
template <precision Q>
@ -138,9 +109,55 @@ namespace glm
, y(static_cast<T>(v.y))
{}
//////////////////////////////////////
// Component accesses
# ifdef GLM_FORCE_SIZE_FUNC
template <typename T, precision P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename tvec2<T, P>::size_type tvec2<T, P>::size() const
{
return 2;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER T & tvec2<T, P>::operator[](typename tvec2<T, P>::size_type i)
{
assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
return (&x)[i];
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER T const & tvec2<T, P>::operator[](typename tvec2<T, P>::size_type i) const
{
assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
return (&x)[i];
}
# else
template <typename T, precision P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename tvec2<T, P>::length_type tvec2<T, P>::length() const
{
return 2;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER T & tvec2<T, P>::operator[](typename tvec2<T, P>::length_type i)
{
assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
return (&x)[i];
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER T const & tvec2<T, P>::operator[](typename tvec2<T, P>::length_type i) const
{
assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
return (&x)[i];
}
# endif//GLM_FORCE_SIZE_FUNC
//////////////////////////////////////
// Unary arithmetic operators
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> & tvec2<T, P>::operator=(tvec2<T, P> const & v)
{
@ -148,6 +165,7 @@ namespace glm
this->y = v.y;
return *this;
}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
template <typename U>

View File

@ -114,8 +114,8 @@ namespace glm
//////////////////////////////////////
// Implicit basic constructors
GLM_FUNC_DECL tvec3();
GLM_FUNC_DECL tvec3(tvec3<T, P> const & v);
GLM_FUNC_DECL tvec3() GLM_DEFAULT;
GLM_FUNC_DECL tvec3(tvec3<T, P> const & v) GLM_DEFAULT;
template <precision Q>
GLM_FUNC_DECL tvec3(tvec3<T, Q> const & v);
@ -184,7 +184,7 @@ namespace glm
//////////////////////////////////////
// Unary arithmetic operators
GLM_FUNC_DECL tvec3<T, P> & operator=(tvec3<T, P> const & v);
GLM_FUNC_DECL tvec3<T, P> & operator=(tvec3<T, P> const & v) GLM_DEFAULT;
template <typename U>
GLM_FUNC_DECL tvec3<T, P> & operator=(tvec3<U, P> const & v);

View File

@ -35,6 +35,7 @@ namespace glm
//////////////////////////////////////
// Implicit basic constructors
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P>::tvec3()
# ifndef GLM_FORCE_NO_CTOR_INIT
@ -46,6 +47,7 @@ namespace glm
GLM_FUNC_QUALIFIER tvec3<T, P>::tvec3(tvec3<T, P> const & v)
: x(v.x), y(v.y), z(v.z)
{}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
template <precision Q>
@ -188,6 +190,7 @@ namespace glm
//////////////////////////////////////
// Unary arithmetic operators
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P>& tvec3<T, P>::operator=(tvec3<T, P> const & v)
{
@ -196,6 +199,7 @@ namespace glm
this->z = v.z;
return *this;
}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
template <typename U>

View File

@ -171,8 +171,8 @@ namespace detail
//////////////////////////////////////
// Implicit basic constructors
GLM_FUNC_DECL tvec4();
GLM_FUNC_DECL tvec4(tvec4<T, P> const & v);
GLM_FUNC_DECL tvec4() GLM_DEFAULT;
GLM_FUNC_DECL tvec4(tvec4<T, P> const & v) GLM_DEFAULT;
template <precision Q>
GLM_FUNC_DECL tvec4(tvec4<T, Q> const & v);
@ -182,7 +182,6 @@ namespace detail
GLM_FUNC_DECL explicit tvec4(ctor);
GLM_FUNC_DECL explicit tvec4(T s);
GLM_FUNC_DECL tvec4(T a, T b, T c, T d);
GLM_FUNC_DECL ~tvec4(){}
//////////////////////////////////////
// Conversion scalar constructors
@ -284,7 +283,7 @@ namespace detail
//////////////////////////////////////
// Unary arithmetic operators
GLM_FUNC_DECL tvec4<T, P> & operator=(tvec4<T, P> const & v);
GLM_FUNC_DECL tvec4<T, P> & operator=(tvec4<T, P> const & v) GLM_DEFAULT;
template <typename U>
GLM_FUNC_DECL tvec4<T, P> & operator=(tvec4<U, P> const & v);

View File

@ -35,6 +35,7 @@ namespace glm
//////////////////////////////////////
// Implicit basic constructors
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P>::tvec4()
# ifndef GLM_FORCE_NO_CTOR_INIT
@ -46,6 +47,7 @@ namespace glm
GLM_FUNC_QUALIFIER tvec4<T, P>::tvec4(tvec4<T, P> const & v)
: x(v.x), y(v.y), z(v.z), w(v.w)
{}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
template <precision Q>
@ -250,6 +252,7 @@ namespace glm
//////////////////////////////////////
// Unary arithmetic operators
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator=(tvec4<T, P> const & v)
{
@ -259,6 +262,7 @@ namespace glm
this->w = v.w;
return *this;
}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
template <typename U>

View File

@ -31,11 +31,8 @@
///////////////////////////////////////////////////////////////////////////////////
namespace glm{
namespace detail
{
}//namespace detail
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template <>
GLM_FUNC_QUALIFIER tvec4<float, lowp>::tvec4()
# ifndef GLM_FORCE_NO_CTOR_INIT
@ -49,6 +46,7 @@ namespace detail
: data(_mm_setzero_ps())
# endif
{}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS
template <>
GLM_FUNC_QUALIFIER tvec4<float, lowp>::tvec4(float s) :

View File

@ -69,6 +69,22 @@ int test_vec1_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
union pack
{
glm::vec1 f;
glm::ivec1 i;
} A, B;
A.f = glm::vec1(0);
Error += glm::all(glm::equal(A.i, glm::ivec1(0))) ? 0 : 1;
B.f = glm::vec1(1);
Error += glm::all(glm::equal(B.i, glm::ivec1(1065353216))) ? 0 : 1;
}
# endif//GLM_HAS_DEFAULTED_FUNCTIONS
# if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::vec1>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::vec1>::value ? 0 : 1;

View File

@ -229,6 +229,22 @@ int test_vec2_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
union pack
{
glm::vec2 f;
glm::ivec2 i;
} A, B;
A.f = glm::vec2(0);
Error += glm::all(glm::equal(A.i, glm::ivec2(0))) ? 0 : 1;
B.f = glm::vec2(1);
Error += glm::all(glm::equal(B.i, glm::ivec2(1065353216))) ? 0 : 1;
}
# endif//GLM_HAS_DEFAULTED_FUNCTIONS
# if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::vec2>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::vec2>::value ? 0 : 1;

View File

@ -45,6 +45,22 @@ int test_vec3_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
union pack
{
glm::vec3 f;
glm::ivec3 i;
} A, B;
A.f = glm::vec3(0);
Error += glm::all(glm::equal(A.i, glm::ivec3(0))) ? 0 : 1;
B.f = glm::vec3(1);
Error += glm::all(glm::equal(B.i, glm::ivec3(1065353216))) ? 0 : 1;
}
# endif//GLM_HAS_DEFAULTED_FUNCTIONS
# if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::vec3>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::vec3>::value ? 0 : 1;

View File

@ -68,6 +68,22 @@ int test_vec4_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
union pack
{
glm::vec4 f;
glm::ivec4 i;
} A, B;
A.f = glm::vec4(0);
Error += glm::all(glm::equal(A.i, glm::ivec4(0))) ? 0 : 1;
B.f = glm::vec4(1);
Error += glm::all(glm::equal(B.i, glm::ivec4(1065353216))) ? 0 : 1;
}
# endif//GLM_HAS_DEFAULTED_FUNCTIONS
{
glm::ivec4 A(1, 2, 3, 4);
glm::ivec4 B(A);