From c2b31a8831d24ac9c531ed47aecef3ca98f9b955 Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Thu, 1 Oct 2015 21:45:47 -0400 Subject: [PATCH] Add metaprogramming constructors to tvec3 - Tests, too --- glm/detail/type_vec3.hpp | 9 +++++++++ glm/detail/type_vec3.inl | 15 +++++++++++++++ test/core/core_type_vec3.cpp | 10 ++++++++++ 3 files changed, 34 insertions(+) diff --git a/glm/detail/type_vec3.hpp b/glm/detail/type_vec3.hpp index 98dd74f8..4a17db5b 100644 --- a/glm/detail/type_vec3.hpp +++ b/glm/detail/type_vec3.hpp @@ -150,6 +150,15 @@ namespace glm template GLM_FUNC_DECL GLM_EXPLICIT tvec3(tvec3 const & v); + /// Extra helper constructors for metaprogramming +# ifdef GLM_META_PROG_HELPERS + template + GLM_FUNC_DECL tvec3(X const& x, Y const& y, Z const& z, W const&); + + template + GLM_FUNC_DECL tvec3(X const& x, Y const& y); +# endif + // -- Swizzle constructors -- # if GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE) diff --git a/glm/detail/type_vec3.inl b/glm/detail/type_vec3.inl index 1e5081d4..0ddb8293 100644 --- a/glm/detail/type_vec3.inl +++ b/glm/detail/type_vec3.inl @@ -140,6 +140,21 @@ namespace glm z(static_cast(v.z)) {} + // -- Metaprogramming helper constructors -- +# ifdef GLM_META_PROG_HELPERS + template + template + GLM_FUNC_QUALIFIER tvec3::tvec3(X const& x, Y const& y, Z const& z, W const&) + : x(static_cast(x)), y(static_cast(y)), z(static_cast(z)) + {} + + template + template + GLM_FUNC_QUALIFIER tvec3::tvec3(X const& x, Y const& y) + : x(static_cast(x)), y(static_cast(y)), z(static_cast(0)) + {} +# endif + // -- Component accesses -- # ifdef GLM_FORCE_SIZE_FUNC diff --git a/test/core/core_type_vec3.cpp b/test/core/core_type_vec3.cpp index 727e90d7..b4d926f1 100644 --- a/test/core/core_type_vec3.cpp +++ b/test/core/core_type_vec3.cpp @@ -45,6 +45,16 @@ int test_vec3_ctor() { int Error = 0; +# ifdef GLM_META_PROG_HELPERS + { + glm::vec3 a(1, 2, 0), b(1, 2, 0, 4), c(1, 2); + + Error += (a == b) ? 0 : 1; + Error += (b == c) ? 0 : 1; + Error += (a == c) ? 0 : 1; + } +# endif + # if GLM_HAS_TRIVIAL_QUERIES // Error += std::is_trivially_default_constructible::value ? 0 : 1; // Error += std::is_trivially_copy_assignable::value ? 0 : 1;