opengl - 如何在 STL 算法中使用 glm 的 operator==?

标签 opengl stl

是否可以在 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/

相关文章:

c++ - 如何在现代 opengl 中处理正交投影中的照明?

c++ - 如何调试 OpenGL 程序?

java - 使用 libgdx 渲染的 3D 对象没有使用搅拌器创建时使用的颜色

c++ - 从多集 C++ 中删除时出现段错误

c++ - 如何更改STL列表中项目的值?

c++ - 着色器中自己的 double cos() 实现的结果是 NaN,但在 CPU 上运行良好。出了什么问题?

c++ - 是否还可以自定义STL vector 的 "reference"类型?

c++ - 使用自定义比较器作为映射构造函数错误中的值的priority_queue

c++ - STL列表,删除所有奇数

linux - Clang OpenGL 和 Max