From 4b6284e39d8e1098a173347eb16651dbb6916efa Mon Sep 17 00:00:00 2001 From: Charles Huber Date: Mon, 25 Jul 2022 10:34:11 -0500 Subject: [PATCH] GCC: Fix noexcept warnings on hash functions Fix warnings on hash functions with GCC and -Wnoexcept: * Add GLM_HAS_NOEXCEPT flag & GLM_NOEXCEPT #define to setup.hpp. * Add GLM_NOEXCEPT to hash functions in hash.hpp. * Add GLM_NOEXCEPT to matrix operator[] accessors. * Add gtx_hash.cpp and a test to verify all hash overloads compile. Configure with -DCMAKE_CXX_FLAGS="-Werror -Wnoexcept" to test. --- glm/detail/setup.hpp | 12 +++++++++ glm/detail/type_mat2x2.hpp | 4 +-- glm/detail/type_mat2x2.inl | 4 +-- glm/detail/type_mat2x3.hpp | 4 +-- glm/detail/type_mat2x3.inl | 4 +-- glm/detail/type_mat2x4.hpp | 4 +-- glm/detail/type_mat2x4.inl | 4 +-- glm/detail/type_mat3x2.hpp | 4 +-- glm/detail/type_mat3x2.inl | 4 +-- glm/detail/type_mat3x3.hpp | 4 +-- glm/detail/type_mat3x3.inl | 4 +-- glm/detail/type_mat3x4.hpp | 4 +-- glm/detail/type_mat3x4.inl | 4 +-- glm/detail/type_mat4x2.hpp | 4 +-- glm/detail/type_mat4x2.inl | 4 +-- glm/detail/type_mat4x3.hpp | 4 +-- glm/detail/type_mat4x3.inl | 4 +-- glm/detail/type_mat4x4.hpp | 4 +-- glm/detail/type_mat4x4.inl | 4 +-- glm/gtx/hash.hpp | 30 ++++++++++----------- glm/gtx/hash.inl | 30 ++++++++++----------- test/gtx/CMakeLists.txt | 1 + test/gtx/gtx_hash.cpp | 55 ++++++++++++++++++++++++++++++++++++++ 23 files changed, 134 insertions(+), 66 deletions(-) create mode 100644 test/gtx/gtx_hash.cpp diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index d9ca27dc..5c575198 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -360,6 +360,18 @@ # define GLM_HAS_BITSCAN_WINDOWS 0 #endif +#if GLM_LANG & GLM_LANG_CXX11_FLAG +# define GLM_HAS_NOEXCEPT 1 +#else +# define GLM_HAS_NOEXCEPT 0 +#endif + +#if GLM_HAS_NOEXCEPT +# define GLM_NOEXCEPT noexcept +#else +# define GLM_NOEXCEPT +#endif + /////////////////////////////////////////////////////////////////////////////////// // OpenMP #ifdef _OPENMP diff --git a/glm/detail/type_mat2x2.hpp b/glm/detail/type_mat2x2.hpp index 827022dd..b2c918c3 100644 --- a/glm/detail/type_mat2x2.hpp +++ b/glm/detail/type_mat2x2.hpp @@ -27,8 +27,8 @@ namespace glm typedef length_t length_type; GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 2; } - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const; + GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT; + GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT; // -- Constructors -- diff --git a/glm/detail/type_mat2x2.inl b/glm/detail/type_mat2x2.inl index 29a5ded0..55e94fe6 100644 --- a/glm/detail/type_mat2x2.inl +++ b/glm/detail/type_mat2x2.inl @@ -217,14 +217,14 @@ namespace glm // -- Accesses -- template - GLM_FUNC_QUALIFIER typename mat<2, 2, T, Q>::col_type& mat<2, 2, T, Q>::operator[](typename mat<2, 2, T, Q>::length_type i) + GLM_FUNC_QUALIFIER typename mat<2, 2, T, Q>::col_type& mat<2, 2, T, Q>::operator[](typename mat<2, 2, T, Q>::length_type i) GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 2, T, Q>::col_type const& mat<2, 2, T, Q>::operator[](typename mat<2, 2, T, Q>::length_type i) const + GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 2, T, Q>::col_type const& mat<2, 2, T, Q>::operator[](typename mat<2, 2, T, Q>::length_type i) const GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; diff --git a/glm/detail/type_mat2x3.hpp b/glm/detail/type_mat2x3.hpp index c9303cba..c02a913e 100644 --- a/glm/detail/type_mat2x3.hpp +++ b/glm/detail/type_mat2x3.hpp @@ -28,8 +28,8 @@ namespace glm typedef length_t length_type; GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 2; } - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const; + GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT; + GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT; // -- Constructors -- diff --git a/glm/detail/type_mat2x3.inl b/glm/detail/type_mat2x3.inl index a5462ce0..ee48e8f8 100644 --- a/glm/detail/type_mat2x3.inl +++ b/glm/detail/type_mat2x3.inl @@ -217,14 +217,14 @@ namespace glm // -- Accesses -- template - GLM_FUNC_QUALIFIER typename mat<2, 3, T, Q>::col_type & mat<2, 3, T, Q>::operator[](typename mat<2, 3, T, Q>::length_type i) + GLM_FUNC_QUALIFIER typename mat<2, 3, T, Q>::col_type & mat<2, 3, T, Q>::operator[](typename mat<2, 3, T, Q>::length_type i) GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 3, T, Q>::col_type const& mat<2, 3, T, Q>::operator[](typename mat<2, 3, T, Q>::length_type i) const + GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 3, T, Q>::col_type const& mat<2, 3, T, Q>::operator[](typename mat<2, 3, T, Q>::length_type i) const GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; diff --git a/glm/detail/type_mat2x4.hpp b/glm/detail/type_mat2x4.hpp index f7697962..b66acb08 100644 --- a/glm/detail/type_mat2x4.hpp +++ b/glm/detail/type_mat2x4.hpp @@ -28,8 +28,8 @@ namespace glm typedef length_t length_type; GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 2; } - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const; + GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT; + GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT; // -- Constructors -- diff --git a/glm/detail/type_mat2x4.inl b/glm/detail/type_mat2x4.inl index 31c7ea2f..72f7d73e 100644 --- a/glm/detail/type_mat2x4.inl +++ b/glm/detail/type_mat2x4.inl @@ -219,14 +219,14 @@ namespace glm // -- Accesses -- template - GLM_FUNC_QUALIFIER typename mat<2, 4, T, Q>::col_type & mat<2, 4, T, Q>::operator[](typename mat<2, 4, T, Q>::length_type i) + GLM_FUNC_QUALIFIER typename mat<2, 4, T, Q>::col_type & mat<2, 4, T, Q>::operator[](typename mat<2, 4, T, Q>::length_type i) GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 4, T, Q>::col_type const& mat<2, 4, T, Q>::operator[](typename mat<2, 4, T, Q>::length_type i) const + GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 4, T, Q>::col_type const& mat<2, 4, T, Q>::operator[](typename mat<2, 4, T, Q>::length_type i) const GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; diff --git a/glm/detail/type_mat3x2.hpp b/glm/detail/type_mat3x2.hpp index d528af03..0ddb65e4 100644 --- a/glm/detail/type_mat3x2.hpp +++ b/glm/detail/type_mat3x2.hpp @@ -28,8 +28,8 @@ namespace glm typedef length_t length_type; GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 3; } - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const; + GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT; + GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT; // -- Constructors -- diff --git a/glm/detail/type_mat3x2.inl b/glm/detail/type_mat3x2.inl index 8cf8ed3f..fcf9447d 100644 --- a/glm/detail/type_mat3x2.inl +++ b/glm/detail/type_mat3x2.inl @@ -236,14 +236,14 @@ namespace glm // -- Accesses -- template - GLM_FUNC_QUALIFIER typename mat<3, 2, T, Q>::col_type & mat<3, 2, T, Q>::operator[](typename mat<3, 2, T, Q>::length_type i) + GLM_FUNC_QUALIFIER typename mat<3, 2, T, Q>::col_type & mat<3, 2, T, Q>::operator[](typename mat<3, 2, T, Q>::length_type i) GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 2, T, Q>::col_type const& mat<3, 2, T, Q>::operator[](typename mat<3, 2, T, Q>::length_type i) const + GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 2, T, Q>::col_type const& mat<3, 2, T, Q>::operator[](typename mat<3, 2, T, Q>::length_type i) const GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; diff --git a/glm/detail/type_mat3x3.hpp b/glm/detail/type_mat3x3.hpp index 9b435aea..7aac3219 100644 --- a/glm/detail/type_mat3x3.hpp +++ b/glm/detail/type_mat3x3.hpp @@ -27,8 +27,8 @@ namespace glm typedef length_t length_type; GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 3; } - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const; + GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT; + GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT; // -- Constructors -- diff --git a/glm/detail/type_mat3x3.inl b/glm/detail/type_mat3x3.inl index 4362d84a..233473e3 100644 --- a/glm/detail/type_mat3x3.inl +++ b/glm/detail/type_mat3x3.inl @@ -238,14 +238,14 @@ namespace glm // -- Accesses -- template - GLM_FUNC_QUALIFIER typename mat<3, 3, T, Q>::col_type & mat<3, 3, T, Q>::operator[](typename mat<3, 3, T, Q>::length_type i) + GLM_FUNC_QUALIFIER typename mat<3, 3, T, Q>::col_type & mat<3, 3, T, Q>::operator[](typename mat<3, 3, T, Q>::length_type i) GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 3, T, Q>::col_type const& mat<3, 3, T, Q>::operator[](typename mat<3, 3, T, Q>::length_type i) const + GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 3, T, Q>::col_type const& mat<3, 3, T, Q>::operator[](typename mat<3, 3, T, Q>::length_type i) const GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; diff --git a/glm/detail/type_mat3x4.hpp b/glm/detail/type_mat3x4.hpp index 27bc425f..c8a1f2cc 100644 --- a/glm/detail/type_mat3x4.hpp +++ b/glm/detail/type_mat3x4.hpp @@ -28,8 +28,8 @@ namespace glm typedef length_t length_type; GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 3; } - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const; + GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT; + GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT; // -- Constructors -- diff --git a/glm/detail/type_mat3x4.inl b/glm/detail/type_mat3x4.inl index c1a0fa6d..43ab3fdd 100644 --- a/glm/detail/type_mat3x4.inl +++ b/glm/detail/type_mat3x4.inl @@ -242,14 +242,14 @@ namespace glm // -- Accesses -- template - GLM_FUNC_QUALIFIER typename mat<3, 4, T, Q>::col_type & mat<3, 4, T, Q>::operator[](typename mat<3, 4, T, Q>::length_type i) + GLM_FUNC_QUALIFIER typename mat<3, 4, T, Q>::col_type & mat<3, 4, T, Q>::operator[](typename mat<3, 4, T, Q>::length_type i) GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 4, T, Q>::col_type const& mat<3, 4, T, Q>::operator[](typename mat<3, 4, T, Q>::length_type i) const + GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 4, T, Q>::col_type const& mat<3, 4, T, Q>::operator[](typename mat<3, 4, T, Q>::length_type i) const GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; diff --git a/glm/detail/type_mat4x2.hpp b/glm/detail/type_mat4x2.hpp index 56f500d7..df51af70 100644 --- a/glm/detail/type_mat4x2.hpp +++ b/glm/detail/type_mat4x2.hpp @@ -28,8 +28,8 @@ namespace glm typedef length_t length_type; GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 4; } - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const; + GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT; + GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT; // -- Constructors -- diff --git a/glm/detail/type_mat4x2.inl b/glm/detail/type_mat4x2.inl index efe58330..8fc4c3b3 100644 --- a/glm/detail/type_mat4x2.inl +++ b/glm/detail/type_mat4x2.inl @@ -255,14 +255,14 @@ namespace glm // -- Accesses -- template - GLM_FUNC_QUALIFIER typename mat<4, 2, T, Q>::col_type & mat<4, 2, T, Q>::operator[](typename mat<4, 2, T, Q>::length_type i) + GLM_FUNC_QUALIFIER typename mat<4, 2, T, Q>::col_type & mat<4, 2, T, Q>::operator[](typename mat<4, 2, T, Q>::length_type i) GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 2, T, Q>::col_type const& mat<4, 2, T, Q>::operator[](typename mat<4, 2, T, Q>::length_type i) const + GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 2, T, Q>::col_type const& mat<4, 2, T, Q>::operator[](typename mat<4, 2, T, Q>::length_type i) const GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; diff --git a/glm/detail/type_mat4x3.hpp b/glm/detail/type_mat4x3.hpp index 5a4668f7..42c0281e 100644 --- a/glm/detail/type_mat4x3.hpp +++ b/glm/detail/type_mat4x3.hpp @@ -28,8 +28,8 @@ namespace glm typedef length_t length_type; GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 4; } - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const; + GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT; + GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT; // -- Constructors -- diff --git a/glm/detail/type_mat4x3.inl b/glm/detail/type_mat4x3.inl index 1249e958..994a9332 100644 --- a/glm/detail/type_mat4x3.inl +++ b/glm/detail/type_mat4x3.inl @@ -255,14 +255,14 @@ namespace glm // -- Accesses -- template - GLM_FUNC_QUALIFIER typename mat<4, 3, T, Q>::col_type & mat<4, 3, T, Q>::operator[](typename mat<4, 3, T, Q>::length_type i) + GLM_FUNC_QUALIFIER typename mat<4, 3, T, Q>::col_type & mat<4, 3, T, Q>::operator[](typename mat<4, 3, T, Q>::length_type i) GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 3, T, Q>::col_type const& mat<4, 3, T, Q>::operator[](typename mat<4, 3, T, Q>::length_type i) const + GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 3, T, Q>::col_type const& mat<4, 3, T, Q>::operator[](typename mat<4, 3, T, Q>::length_type i) const GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; diff --git a/glm/detail/type_mat4x4.hpp b/glm/detail/type_mat4x4.hpp index b92e2080..dd3c5f81 100644 --- a/glm/detail/type_mat4x4.hpp +++ b/glm/detail/type_mat4x4.hpp @@ -27,8 +27,8 @@ namespace glm typedef length_t length_type; GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 4;} - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const; + GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT; + GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT; // -- Constructors -- diff --git a/glm/detail/type_mat4x4.inl b/glm/detail/type_mat4x4.inl index 5c2166ea..2a82bbab 100644 --- a/glm/detail/type_mat4x4.inl +++ b/glm/detail/type_mat4x4.inl @@ -286,14 +286,14 @@ namespace glm // -- Accesses -- template - GLM_FUNC_QUALIFIER typename mat<4, 4, T, Q>::col_type & mat<4, 4, T, Q>::operator[](typename mat<4, 4, T, Q>::length_type i) + GLM_FUNC_QUALIFIER typename mat<4, 4, T, Q>::col_type & mat<4, 4, T, Q>::operator[](typename mat<4, 4, T, Q>::length_type i) GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; } template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 4, T, Q>::col_type const& mat<4, 4, T, Q>::operator[](typename mat<4, 4, T, Q>::length_type i) const + GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 4, T, Q>::col_type const& mat<4, 4, T, Q>::operator[](typename mat<4, 4, T, Q>::length_type i) const GLM_NOEXCEPT { assert(i < this->length()); return this->value[i]; diff --git a/glm/gtx/hash.hpp b/glm/gtx/hash.hpp index 05dae9f4..1601428d 100644 --- a/glm/gtx/hash.hpp +++ b/glm/gtx/hash.hpp @@ -51,91 +51,91 @@ namespace std template struct hash > { - GLM_FUNC_DECL size_t operator()(glm::vec<1, T, Q> const& v) const; + GLM_FUNC_DECL size_t operator()(glm::vec<1, T, Q> const& v) const GLM_NOEXCEPT; }; template struct hash > { - GLM_FUNC_DECL size_t operator()(glm::vec<2, T, Q> const& v) const; + GLM_FUNC_DECL size_t operator()(glm::vec<2, T, Q> const& v) const GLM_NOEXCEPT; }; template struct hash > { - GLM_FUNC_DECL size_t operator()(glm::vec<3, T, Q> const& v) const; + GLM_FUNC_DECL size_t operator()(glm::vec<3, T, Q> const& v) const GLM_NOEXCEPT; }; template struct hash > { - GLM_FUNC_DECL size_t operator()(glm::vec<4, T, Q> const& v) const; + GLM_FUNC_DECL size_t operator()(glm::vec<4, T, Q> const& v) const GLM_NOEXCEPT; }; template struct hash> { - GLM_FUNC_DECL size_t operator()(glm::qua const& q) const; + GLM_FUNC_DECL size_t operator()(glm::qua const& q) const GLM_NOEXCEPT; }; template struct hash > { - GLM_FUNC_DECL size_t operator()(glm::tdualquat const& q) const; + GLM_FUNC_DECL size_t operator()(glm::tdualquat const& q) const GLM_NOEXCEPT; }; template struct hash > { - GLM_FUNC_DECL size_t operator()(glm::mat<2, 2, T,Q> const& m) const; + GLM_FUNC_DECL size_t operator()(glm::mat<2, 2, T,Q> const& m) const GLM_NOEXCEPT; }; template struct hash > { - GLM_FUNC_DECL size_t operator()(glm::mat<2, 3, T,Q> const& m) const; + GLM_FUNC_DECL size_t operator()(glm::mat<2, 3, T,Q> const& m) const GLM_NOEXCEPT; }; template struct hash > { - GLM_FUNC_DECL size_t operator()(glm::mat<2, 4, T,Q> const& m) const; + GLM_FUNC_DECL size_t operator()(glm::mat<2, 4, T,Q> const& m) const GLM_NOEXCEPT; }; template struct hash > { - GLM_FUNC_DECL size_t operator()(glm::mat<3, 2, T,Q> const& m) const; + GLM_FUNC_DECL size_t operator()(glm::mat<3, 2, T,Q> const& m) const GLM_NOEXCEPT; }; template struct hash > { - GLM_FUNC_DECL size_t operator()(glm::mat<3, 3, T,Q> const& m) const; + GLM_FUNC_DECL size_t operator()(glm::mat<3, 3, T,Q> const& m) const GLM_NOEXCEPT; }; template struct hash > { - GLM_FUNC_DECL size_t operator()(glm::mat<3, 4, T,Q> const& m) const; + GLM_FUNC_DECL size_t operator()(glm::mat<3, 4, T,Q> const& m) const GLM_NOEXCEPT; }; template struct hash > { - GLM_FUNC_DECL size_t operator()(glm::mat<4, 2, T,Q> const& m) const; + GLM_FUNC_DECL size_t operator()(glm::mat<4, 2, T,Q> const& m) const GLM_NOEXCEPT; }; template struct hash > { - GLM_FUNC_DECL size_t operator()(glm::mat<4, 3, T,Q> const& m) const; + GLM_FUNC_DECL size_t operator()(glm::mat<4, 3, T,Q> const& m) const GLM_NOEXCEPT; }; template struct hash > { - GLM_FUNC_DECL size_t operator()(glm::mat<4, 4, T,Q> const& m) const; + GLM_FUNC_DECL size_t operator()(glm::mat<4, 4, T,Q> const& m) const GLM_NOEXCEPT; }; } // namespace std diff --git a/glm/gtx/hash.inl b/glm/gtx/hash.inl index ff71ca9f..5bb0c387 100644 --- a/glm/gtx/hash.inl +++ b/glm/gtx/hash.inl @@ -22,14 +22,14 @@ namespace detail namespace std { template - GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::vec<1, T, Q> const& v) const + GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::vec<1, T, Q> const& v) const GLM_NOEXCEPT { hash hasher; return hasher(v.x); } template - GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::vec<2, T, Q> const& v) const + GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::vec<2, T, Q> const& v) const GLM_NOEXCEPT { size_t seed = 0; hash hasher; @@ -39,7 +39,7 @@ namespace std } template - GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::vec<3, T, Q> const& v) const + GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::vec<3, T, Q> const& v) const GLM_NOEXCEPT { size_t seed = 0; hash hasher; @@ -50,7 +50,7 @@ namespace std } template - GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::vec<4, T, Q> const& v) const + GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::vec<4, T, Q> const& v) const GLM_NOEXCEPT { size_t seed = 0; hash hasher; @@ -62,7 +62,7 @@ namespace std } template - GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::qua const& q) const + GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::qua const& q) const GLM_NOEXCEPT { size_t seed = 0; hash hasher; @@ -74,7 +74,7 @@ namespace std } template - GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::tdualquat const& q) const + GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::tdualquat const& q) const GLM_NOEXCEPT { size_t seed = 0; hash> hasher; @@ -84,7 +84,7 @@ namespace std } template - GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<2, 2, T, Q> const& m) const + GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<2, 2, T, Q> const& m) const GLM_NOEXCEPT { size_t seed = 0; hash> hasher; @@ -94,7 +94,7 @@ namespace std } template - GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<2, 3, T, Q> const& m) const + GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<2, 3, T, Q> const& m) const GLM_NOEXCEPT { size_t seed = 0; hash> hasher; @@ -104,7 +104,7 @@ namespace std } template - GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<2, 4, T, Q> const& m) const + GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<2, 4, T, Q> const& m) const GLM_NOEXCEPT { size_t seed = 0; hash> hasher; @@ -114,7 +114,7 @@ namespace std } template - GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<3, 2, T, Q> const& m) const + GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<3, 2, T, Q> const& m) const GLM_NOEXCEPT { size_t seed = 0; hash> hasher; @@ -125,7 +125,7 @@ namespace std } template - GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<3, 3, T, Q> const& m) const + GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<3, 3, T, Q> const& m) const GLM_NOEXCEPT { size_t seed = 0; hash> hasher; @@ -136,7 +136,7 @@ namespace std } template - GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<3, 4, T, Q> const& m) const + GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<3, 4, T, Q> const& m) const GLM_NOEXCEPT { size_t seed = 0; hash> hasher; @@ -147,7 +147,7 @@ namespace std } template - GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<4, 2, T,Q> const& m) const + GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<4, 2, T,Q> const& m) const GLM_NOEXCEPT { size_t seed = 0; hash> hasher; @@ -159,7 +159,7 @@ namespace std } template - GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<4, 3, T,Q> const& m) const + GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<4, 3, T,Q> const& m) const GLM_NOEXCEPT { size_t seed = 0; hash> hasher; @@ -171,7 +171,7 @@ namespace std } template - GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<4, 4, T, Q> const& m) const + GLM_FUNC_QUALIFIER size_t hash>::operator()(glm::mat<4, 4, T, Q> const& m) const GLM_NOEXCEPT { size_t seed = 0; hash> hasher; diff --git a/test/gtx/CMakeLists.txt b/test/gtx/CMakeLists.txt index ad7bf492..6fdb1398 100644 --- a/test/gtx/CMakeLists.txt +++ b/test/gtx/CMakeLists.txt @@ -18,6 +18,7 @@ glmCreateTestGTC(gtx_fast_trigonometry) glmCreateTestGTC(gtx_functions) glmCreateTestGTC(gtx_gradient_paint) glmCreateTestGTC(gtx_handed_coordinate_space) +glmCreateTestGTC(gtx_hash) glmCreateTestGTC(gtx_integer) glmCreateTestGTC(gtx_intersect) glmCreateTestGTC(gtx_io) diff --git a/test/gtx/gtx_hash.cpp b/test/gtx/gtx_hash.cpp new file mode 100644 index 00000000..a3d43144 --- /dev/null +++ b/test/gtx/gtx_hash.cpp @@ -0,0 +1,55 @@ +#define GLM_ENABLE_EXPERIMENTAL +#include +#include + +int test_compile() +{ + int Error = 0; + + // Vector types + std::unordered_map map_vec1; + Error += ++map_vec1[glm::vec1(0.0f)]; + std::unordered_map map_vec2; + Error += ++map_vec2[glm::vec2(0.0f)]; + std::unordered_map map_vec3; + Error += ++map_vec3[glm::vec3(0.0f)]; + std::unordered_map map_vec4; + Error += ++map_vec4[glm::vec4(0.0f)]; + + // Quaternion types + std::unordered_map map_quat; + Error += ++map_quat[glm::quat(0.0f, glm::vec3(0.0f))]; + std::unordered_map map_dualquat; + Error += ++map_dualquat[glm::dualquat(glm::vec3(0.0f))]; + + // Matrix types + std::unordered_map map_mat2x2; + Error += ++map_mat2x2[glm::mat2x2(0.0f)]; + std::unordered_map map_mat2x3; + Error += ++map_mat2x3[glm::mat2x3(0.0f)]; + std::unordered_map map_mat2x4; + Error += ++map_mat2x4[glm::mat2x4(0.0f)]; + std::unordered_map map_mat3x2; + Error += ++map_mat3x2[glm::mat3x2(0.0f)]; + std::unordered_map map_mat3x3; + Error += ++map_mat3x3[glm::mat3x3(0.0f)]; + std::unordered_map map_mat3x4; + Error += ++map_mat3x4[glm::mat3x4(0.0f)]; + std::unordered_map map_mat4x2; + Error += ++map_mat4x2[glm::mat4x2(0.0f)]; + std::unordered_map map_mat4x3; + Error += ++map_mat4x3[glm::mat4x3(0.0f)]; + std::unordered_map map_mat4x4; + Error += ++map_mat4x4[glm::mat4x4(0.0f)]; + + return Error > 0 ? 0 : 1; +} + +int main() +{ + int Error = 0; + + Error += test_compile(); + + return Error; +} \ No newline at end of file