How to overload operator == for (TArray)?

Hi, I want to use Array_Find function in C++, so how i can overload the missing operator?
I know it will need to rebuild the engine, so i have no other choice , i am ready to rebuild the engine so please help me

template<typename T, typename U>
	static int32 Array_Find(const TArray<T>& TargetArray, const U& ItemToFind)
	{
		return TargetArray.Find(ItemToFind);
	}

implementing this function gives an error.

int32 Index;
FTransform Location;
TArray<FTransform> TransformArray;
bool bEqualValid ;

Index = FCustomThunkTemplates::Array_Find(TransformArray, Location);
example:

Index = FCustomThunkTemplates::Array_Find(TransformArray, Location);
bEqualValid = UKismetMathLibrary::EqualEqual_IntInt(Index, -1);

ERROR::

binary ‘==’: no operator found which takes a left-hand operand of type ‘const FTransform’ (or there is no acceptable conversion) Containers\Array.h

Still trying to fit an “int” into an “F transform”, I see.

If I were you I would return a float above directly in the return statement.

It’s the last line giving the error Location is an Ftransform type and you are trying to store it to Index that is an int. There is no engine error, you want to modify the engine so a int accepts a ftransform. Counting it’s a template type and you want to store the tepmlate to int.

I don’t know what is behind this

FCustomThunkTemplates::Array_Find

It might be that this makes a conversion possible, but I doubt it.

1 Like

yes Sir i am still struggling with this, i can’t leave it without solving

this is find function, the Array_Find is returning it.

SizeType Find(const ElementType& Item) const
	{
		const ElementType* RESTRICT Start = GetData();
		for (const ElementType* RESTRICT Data = Start, *RESTRICT DataEnd = Data + ArrayNum; Data != DataEnd; ++Data)
		{
			if (*Data == Item)
			{
				return static_cast<SizeType>(Data - Start);
			}
		}
		return INDEX_NONE;
	}```

It’s a strange for loop, I never seen it like this. " but you can tell that it’s counting with ++Data"
It’s counting the variable Data and as in counts if it encounters something identical like in the Item it returns a static_cast, or as I see at the end a range between Data and Start. There is no conversion elements here.

I don’t think there is anything wrong with this, your addition is wrong that you are trying to store it to int.

1 Like

Dont use Array_Find it works behind the scene on memory level for registered products instances, you can do it manually but it will have a huge risk of memory leak, I recommend to use ContainsByPredicate using do|while loop , but you can overload == and != for int = transfromArrayElements.find(TransformElement)


hope it heps
cheers!

1 Like

Sir I don’t store it to int, I find the Ftransform data in Ftransform Array variable and then during this search of data between them I am sure there is an index which I am storing in int
This find function is returning an integer

Sir I am tired trying this do/while loop, it freezes the engine and i have to close it through visual studio clicking the stop button

no way it can freez the engine, post your code, you are probably doing something wrong with the loop

Index = FCustomThunkTemplates::Array_Find(TransformArray, Location);

Index is of type int, and you want to store the static call function with the paremeters inserted to int. This is a call on a function with parameters

What is that there

		return INDEX_NONE;

Is it placed by you there ?
This is a hint that it does not return numerical whole indexes, exactly what you are doing.

1 Like

I created the native code of this find function

do
	{
		RandomLocation(Available, Location);
	} while (UsedLocations.ContainsByPredicate([Location](const FTransform Transform)
	{
		return Transform.GetLocation() == Location.GetLocation()
			&& Transform.GetRotation() == Location.GetRotation()
			&& Transform.GetScale3D() == Location.GetScale3D();
	}));
	SpawnLocation = Location;
	UsedLocations.Add(SpawnLocation);

no, not by me, its already in the file

its already in the file, not by me

what I can see is your loop is infinite and you are doing this on the reverse direction :rofl:

Sir I am confused, can you please fix it so I can se what was wrong :tired_face:

Well the error is clear, it refers to conversions from one type to other type.
no operator found which takes a left-hand operand of type ‘const FTransform’

1
So it’s a type FTransform that you are fiting inside “Index”
This is the actual error and because of this you got an error with type Ftransform.

2
You are putting an FTransform as a parameter on a function call and maybe that function does not contain an Ftransform there for you are trying to convert a parameter to Ftransfrom

It’s either one or two, or maybe bolth.

Tell me here, where do you see an Ftransfrom type here

SizeType Find(const ElementType& Item) const
	{
		const ElementType* RESTRICT Start = GetData();
		for (const ElementType* RESTRICT Data = Start, *RESTRICT DataEnd = Data + ArrayNum; Data != DataEnd; ++Data)
		{
			if (*Data == Item)
			{
				return static_cast<SizeType>(Data - Start);
			}
		}
		return INDEX_NONE;
	}```

The types here are not of Ftrasnfrom ? nor floats ?
Yet you put an Ftransform as a type inside the parameter of the function call.

1 Like

I don’t see it , you are right :slightly_smiling_face:

Fist you need to have a condition setter the loop will follow when to stop and continue.
lets take a bool value false/true.

myclass.cpp

do
	{
		SpawnLocation = Location;
		UsedLocations.Add(SpawnLocation);
	    break;
	} 
	while (UsedLocations.ContainsByPredicate([Location](const FTransform Transform)
	{
		return Transform.GetLocation() == Location.GetLocation();
	}));
		RandomLocation(Available, Location); //do this if the locations are not unique

hope it helps, cheers!

1 Like