如何在stl算法中使用glm的运算符==?
是否可以在 stl 算法中使用 glm::gtx::comparison 中定义的运算符?
具体来说,我有这段代码:
std::vector<glm::ivec3> vecA, vecB; // vectors with content
bool result = std::equal(vecA.begin(), vecA.end(), vecB.begin());
默认情况下会失败,因为找不到运算符==。
Is it possible to use the operators defined in glm::gtx::comparison in stl algorithms?
Specifically 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 fails cause operator== can't be found.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
虽然晚了几年,但我想分享我的解决方案。
我需要 std::map 和 std::set 的比较器函数。
经过一番修补后,我找到了
在头文件 util_glm.hpp 中包含以下代码的解决方案,并将其包含在需要比较器的位置,
我确信可以为 glm::ivec3 完成类似的解决方案
Only a few years late, but I wanted to share my fix.
I needed a comparator function for std::map and std::set.
After a bit of tinkering, I found the solution to have the following code
in a header file util_glm.hpp and include it where ever the comparator was needed with
I am sure a similar solution can be done for glm::ivec3
显然,这是一个未解决的错误。
That's an open bug apparently.
您可以在 virtrev/ 目录中#include equal_operator.hpp。
You can #include equal_operator.hpp, in the virtrev/ directory.
为了能够在
std::set
中使用glm::vec3
,我在 type_vec3.inl 中实现了以下重载:不幸的是我不知道如何在不更改glm代码的情况下实现它。
该实现认为 x 轴比 y 轴更相关,并且 y 轴比 z 更相关,关于小于。更改代码以使任何其他轴更相关非常简单。
==
运算符已实现。To be able to use
glm::vec3
in astd::set<>
, I implemented the following overload in the type_vec3.inl:Unfortunately I don't know how to implement it without change the glm code.
This implementation consider x axis more relevant than y axis and y axis more relevant then z concerning smaller than. It's very simple to change the code to make any other axis more relevant.
The
==
operator is already implemented.