Skip to content

Commit

Permalink
Added support of defaulted functions to *vec* types #366
Browse files Browse the repository at this point in the history
  • Loading branch information
Groovounet committed Jul 24, 2015
1 parent 063c5c7 commit f7751bf
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 131 deletions.
9 changes: 8 additions & 1 deletion glm/detail/setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions glm/detail/type_vec1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
36 changes: 20 additions & 16 deletions glm/detail/type_vec1.inl
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ namespace glm
//////////////////////////////////////
// Implicit basic constructors

template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec1<T, P>::tvec1()
# ifndef GLM_FORCE_NO_CTOR_INIT
: x(0)
# endif
{}
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec1<T, P>::tvec1()
# ifndef GLM_FORCE_NO_CTOR_INIT
: x(0)
# endif
{}

template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec1<T, P>::tvec1(tvec1<T, P> const & v)
: x(v.x)
{}
template <typename T, precision P>
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>
Expand Down Expand Up @@ -140,12 +142,14 @@ namespace glm
//////////////////////////////////////
// Unary arithmetic operators

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;
}
# 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>
Expand Down
6 changes: 3 additions & 3 deletions glm/detail/type_vec2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
114 changes: 66 additions & 48 deletions glm/detail/type_vec2.inl
Original file line number Diff line number Diff line change
Expand Up @@ -28,51 +28,22 @@

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

template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P>::tvec2()
# ifndef GLM_FORCE_NO_CTOR_INIT
: x(0), y(0)
# endif
{}
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P>::tvec2()
# ifndef GLM_FORCE_NO_CTOR_INIT
: x(0), y(0)
# endif
{}

template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P>::tvec2(tvec2<T, P> const & v)
: x(v.x), y(v.y)
{}
template <typename T, precision P>
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>
Expand Down Expand Up @@ -138,16 +109,63 @@ 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

template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> & tvec2<T, P>::operator=(tvec2<T, P> const & v)
{
this->x = v.x;
this->y = v.y;
return *this;
}
# 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)
{
this->x = v.x;
this->y = v.y;
return *this;
}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS

template <typename T, precision P>
template <typename U>
Expand Down
6 changes: 3 additions & 3 deletions glm/detail/type_vec3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
40 changes: 22 additions & 18 deletions glm/detail/type_vec3.inl
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ namespace glm
//////////////////////////////////////
// Implicit basic constructors

template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P>::tvec3()
# ifndef GLM_FORCE_NO_CTOR_INIT
: x(0), y(0), z(0)
# endif
{}
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P>::tvec3()
# ifndef GLM_FORCE_NO_CTOR_INIT
: x(0), y(0), z(0)
# endif
{}

template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P>::tvec3(tvec3<T, P> const & v)
: x(v.x), y(v.y), z(v.z)
{}
template <typename T, precision P>
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>
Expand Down Expand Up @@ -188,14 +190,16 @@ namespace glm
//////////////////////////////////////
// Unary arithmetic operators

template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P>& tvec3<T, P>::operator=(tvec3<T, P> const & v)
{
this->x = v.x;
this->y = v.y;
this->z = v.z;
return *this;
}
# 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)
{
this->x = v.x;
this->y = v.y;
this->z = v.z;
return *this;
}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS

template <typename T, precision P>
template <typename U>
Expand Down
7 changes: 3 additions & 4 deletions glm/detail/type_vec4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit f7751bf

Please sign in to comment.