TMap::Contains() returning true when it should be false

I have a TMap which uses a custom type as a key. This type is based on two enums.

struct CustomType {
	enum class EOne { A, B, C };
	enum class ETwo { X, Y, Z };
	EOne one;
	ETwo two;
	bool operator==(const CustomType& t) const {
		return (one == t.one) && (two == t.two);
	}
	friend inline uint32 GetTypeHash(const CustomType& t) {
		return (uint8_t)t.one + 3 + (uint8_t)t.two;
	}
};

Say the TMap is called map. It contains the following key:

{EOne::A, ETwo::Y}

When I run map.Contains({EOne:A, ETwo::X}), true is returned even if it’s technically false. In fact, I get the value with the key containing {EOne::A, ETwo::Y} instead. I don’t think that this a problem with my hash function, because the two keys won’t overwrite each other if I add them into the map.

Is there another function I need to be overwriting to get this working properly? What else could be the problem?

Hi,

i can’t see in your example what is or how defined “TMap”, are you trying use standart C++ container called “map”? also note that in C++ boolean actually like an integer in memory and any non 0 values are true

p.s. for everyone who may read this:

to enlarge pictures right click it and select “open in new tab”, answerhub doesn’t handle this yet in 1 click on image

don’t forget mark question as answered with little gray circle button under any answer (not comment, but whole answer) when problem solved, so anyone else later can have same question and may find solution faster, if you find solution on your own, don’t forget write it too

TMap is a native UE4 container.

Apparently there was just a silly logic error in the equals operator. While I’m not sure if that’s the right way to define a hash function, what I have up there certainly works.