是否可以在stl算法中使用glm :: gtx :: comparison中定義的運算符?如何在stl算法中使用glm的運算符==?
具體我有這樣的代碼:
std::vector<glm::ivec3> vecA, vecB; // vectors with content
bool result = std::equal(vecA.begin(), vecA.end(), vecB.begin());
此默認失敗導致操作員==無法找到。
是否可以在stl算法中使用glm :: gtx :: comparison中定義的運算符?如何在stl算法中使用glm的運算符==?
具體我有這樣的代碼:
std::vector<glm::ivec3> vecA, vecB; // vectors with content
bool result = std::equal(vecA.begin(), vecA.end(), vecB.begin());
此默認失敗導致操作員==無法找到。
顯然這是一個open bug。
您可以在virtrev /目錄中#include equal_operator.hpp。
「virtrev/equal_operator.hpp」包含在「glm/ext.hpp」中,所以這樣做沒有解決問題。 – fho 2010-10-18 15:04:49
爲了能夠在std::set<>
使用glm::vec3
,我採取了以下過載的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;
}
不幸的是,我不知道如何實現它,而不改變GLM代碼。
該實施方式認爲x軸與y軸更相關,y軸更相關,然後z小於y軸。更改代碼以使其他軸更加相關非常簡單。
==
運營商已經實施。
只遲了幾年,但我想分享我的修復。 我需要一個比較函數std :: map和std :: set。
位的修補後,我發現該溶液具有在頭文件util_glm.hpp以下代碼
#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
和包括它在以往任何時候需要用
#include "util_glm.hpp"
比較我相信可以做類似的解決方案glm :: ivec3
已經晚了:) – fho 2015-01-24 12:08:36
啊好的...應該考慮該選項;) – fho 2010-10-11 07:19:58