I’m trying to map::insert a key datatype I define (miniVec2ui).. It Breaks during a compare (it has bogus data when comparing).. It’s using the standard less functor (i tried with my own, but same problem) – it’s passing rhs.x = ??? and rhs.y = ??? basically. The code is below
miniVec2ui v233 = miniVec2ui(x,y);
m_pIdMap->insert(std::pair<miniVec2ui,uint>(v233,(uint)tmpPF.id));// std::pair<const miniVec2ui,uint>(v233, (uint)tmpPF.id) );
//////in other files I defined miniVec2ui,etc. (uint = unsigned int), tmpPF.id unimportant here, uint x; uint y;
typedef std::map<miniVec2ui,uint> eIdMap;
eIdMap *m_pIdMap;
m_pIdMap = new eIdMap;//new std::map<miniVec2ui, uint >;
struct miniVec2ui {
uint x;
uint y;
miniVec2ui(uint inx, uint iny):
x(inx)
,y(iny) { }
bool operator==(const miniVec2ui& rhs) const {
return ((x == rhs.x) && (y == rhs.y));
}
bool operator!=(const miniVec2ui& rhs) const {
return ( (x != rhs.x) || (y != rhs.y) );
}
bool operator< (const miniVec2ui& rhs) const {
return ((x < rhs.x) && (y < rhs.y));
}
bool operator> (const miniVec2ui& rhs) const {
return ((x > rhs.x) && (y > rhs.y));
}
};
Specifically – breaking in _function_base.h with __y is {x=???,y=???}… here’s the disassembly:
...stuff...
#endif
{
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
200439C0 55 push ebp
200439C1 8B EC mov ebp,esp
200439C3 81 EC CC 00 00 00 sub esp,0CCh
200439C9 53 push ebx
200439CA 56 push esi
200439CB 57 push edi
200439CC 51 push ecx
200439CD 8D BD 34 FF FF FF lea edi,[ebp-0CCh]
200439D3 B9 33 00 00 00 mov ecx,33h
200439D8 B8 CC CC CC CC mov eax,0CCCCCCCCh
200439DD F3 AB rep stos dword ptr es:[edi]
200439DF 59 pop ecx
200439E0 89 4D F8 mov dword ptr [ebp-8],ecx
200439E3 8B 45 0C mov eax,dword ptr [__y]
200439E6 50 push eax
200439E7 8B 4D 08 mov ecx,dword ptr [__x]
200439EA E8 67 84 F1 FF call miniVec2ui::operator< (1FF5BE56h)
200439EF 5F pop edi <--------------------- HERE ---------- <<
I have no idea if it is related to the error you are finding, but your less-than comparison is supposed to implement strict weak ordering, and it doesn’t:
By this logic,
m1is not less thanm2, andm2is not less thanm1:std::map uses this condition to determine whether two elements are equal. You probably need something like
You should try to implement
operator>in terms ofoperator<andoperator!=in terms ofoperator==.