Add metaprogramming constructors to tvec3

- Tests, too
This commit is contained in:
Jesse Talavera-Greenberg 2015-10-01 21:45:47 -04:00
parent 63a087a2e6
commit c2b31a8831
3 changed files with 34 additions and 0 deletions

View File

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

View File

@ -140,6 +140,21 @@ namespace glm
z(static_cast<T>(v.z)) z(static_cast<T>(v.z))
{} {}
// -- 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 tvec3<T, P>::tvec3(X const& x, Y const& y, Z const& z, W const&)
: x(static_cast<T>(x)), y(static_cast<T>(y)), z(static_cast<T>(z))
{}
template <typename T, precision P>
template <typename X, typename Y>
GLM_FUNC_QUALIFIER tvec3<T, P>::tvec3(X const& x, Y const& y)
: x(static_cast<T>(x)), y(static_cast<T>(y)), z(static_cast<T>(0))
{}
# endif
// -- Component accesses -- // -- Component accesses --
# ifdef GLM_FORCE_SIZE_FUNC # ifdef GLM_FORCE_SIZE_FUNC

View File

@ -45,6 +45,16 @@ int test_vec3_ctor()
{ {
int Error = 0; 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 # if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::vec3>::value ? 0 : 1; // Error += std::is_trivially_default_constructible<glm::vec3>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::vec3>::value ? 0 : 1; // Error += std::is_trivially_copy_assignable<glm::vec3>::value ? 0 : 1;