How to use the glm == operator in stl algorithms?

Is it possible to use the operators defined in glm :: gtx :: comparison in stl-algorithms?

In particular, I have this code:

std::vector<glm::ivec3> vecA, vecB; // vectors with content bool result = std::equal(vecA.begin(), vecA.end(), vecB.begin()); 

This by default does not mean that the == operator cannot be found.

+4
source share
4 answers

It seems to open an error .

+1
source

Only a few years later, but I wanted to share my decision. I need a comparator function for std :: map and std :: set.

After messing around a bit, I found a solution to have the following code

 #ifndef __UTIL_GLM__ #define __UTIL_GLM__ #include "glm/vec2.hpp" namespace glm{ template <typename T, precision P> bool operator<(const tvec2<T, P>& a,const tvec2<T, P>& b) { return (ax < bx || (ax == bx && ay < by)); } }; #endif 

in the util_glm.hpp header file and include it where a comparator with

 #include "util_glm.hpp" 

I am sure that a similar solution can be performed for glm :: ivec3

+2
source

You can # enable equal_operator.hpp in the virtrev / directory.

0
source

To be able to use glm::vec3 in std::set<> , I applied the following overload in type_vec3.inl :

 template <typename T> GLM_FUNC_QUALIFIER bool operator< ( tvec3<T> const & v1, tvec3<T> const & v2 ) { if(v1.x == v2.x && v1.y == v2.y && v1.z < v2.z) return true; if(v1.x == v2.x && v1.y < v2.y) return true; if(v1.x < v2.x) return true; return false; } 

Unfortunately, I do not know how to implement it without changing the glm code.

In this implementation, consider an x ​​axis that is more relevant than the y axis and a y axis that is more relevant than the z relatively smaller. It is very simple to change the code to make any other axis more relevant.

The == operator is already implemented.

0
source

All Articles