是否可以在 STL 算法中使用 glm::gtx::comparison 中定义的运算符?
具体来说,我有这个代码:
std::vector<glm::ivec3> vecA, vecB; // vectors with content
bool result = std::equal(vecA.begin(), vecA.end(), vecB.begin());
默认情况下,这会失败,因为找不到 operator==。
最佳答案
只晚了几年,但我想分享我的修复。
我需要一个用于 std::map 和 std::set 的比较器函数。
经过一番修修补补,我找到了具有以下代码的解决方案
#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 (a.x < b.x || (a.x == b.x && a.y < b.y));
}
};
#endif
在头文件 util_glm.hpp 中,并将其包含在需要比较器的地方
#include "util_glm.hpp"
我确信可以为 glm::ivec3 完成类似的解决方案
关于opengl - 如何在 STL 算法中使用 glm 的 operator==?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3891497/