Add metaprogramming helper constructors for tvec2

- Tests, too
This commit is contained in:
Jesse Talavera-Greenberg 2015-10-01 21:44:15 -04:00
parent 51cbb47f3f
commit 63a087a2e6
3 changed files with 25 additions and 0 deletions

View File

@ -140,6 +140,12 @@ namespace glm
template <typename U, precision Q> template <typename U, precision Q>
GLM_FUNC_DECL GLM_EXPLICIT tvec2(tvec2<U, Q> const & v); GLM_FUNC_DECL GLM_EXPLICIT tvec2(tvec2<U, Q> const & v);
/// Extra helper constructors for metaprogramming
# ifdef GLM_META_PROG_HELPERS
template <typename X, typename Y, typename Z, typename W = Z>
GLM_FUNC_DECL tvec2(X const& x, Y const& y, Z const& z, W const& w = W(0));
# endif
// -- Swizzle constructors -- // -- Swizzle constructors --
# if GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE) # if GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)

View File

@ -107,6 +107,15 @@ namespace glm
, y(static_cast<T>(v.y)) , y(static_cast<T>(v.y))
{} {}
// -- Metaprogramming helper constructors --
# ifdef GLM_META_PROG_HELPERS
template <typename T, precision P>
template <typename X, typename Y, typename Z, typename W>
GLM_FUNC_QUALIFIER tvec2<T, P>::tvec2(X const& x, Y const& y, Z const&, W const&)
: x(static_cast<T>(x)), y(static_cast<T>(y))
{}
# endif
// -- Component accesses -- // -- Component accesses --
# ifdef GLM_FORCE_SIZE_FUNC # ifdef GLM_FORCE_SIZE_FUNC

View File

@ -235,6 +235,16 @@ int test_vec2_ctor()
Error += A == B ? 0 : 1; Error += A == B ? 0 : 1;
} }
# ifdef GLM_META_PROG_HELPERS
{
glm::vec2 a(1, 2), b(1, 2, 3), c(1, 2, 3, 4);
Error += (a == b) ? 0 : 1;
Error += (b == c) ? 0 : 1;
Error += (c == a) ? 0 : 1;
}
# endif
# if GLM_HAS_TRIVIAL_QUERIES # if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::vec2>::value ? 0 : 1; // Error += std::is_trivially_default_constructible<glm::vec2>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::vec2>::value ? 0 : 1; // Error += std::is_trivially_copy_assignable<glm::vec2>::value ? 0 : 1;