Make a Custom TMap (ish)

Hey guys,

Today I’m curious on a more complex topic. I’m interested in creating something similar to a TMap Template Class (although instead of it being compatible with ElementType, with class T); however, I have never done it before (neither within UE4’s application context nor any language). So far I’ve been storing said information within UStructs but as I need more variations, I’ve had to manually create Ustruct classes. I know that this is not the path to take and thus I’m looking for help. I have checked a couple of container classes inside UE4’s source code but am still not sure how to go about it. I would rather make one myself and not inherit from TSortableMaps.

Could anyone point me in what direction to take?

an Example of what I currently have (works perfectly but If I want an intFname or any different I’d have to create a custom pair of structures). I have a lot of functions to make for this in mind but I’m hesitant to begin implementing them until I can find a way to not have to copy + paste them every time I need a variation.

USTRUCT(BlueprintType) struct FMakeKeyFNameInt 
{
	GENERATED_BODY()
	
	//
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Data")
	FName Entry;
	
	//
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Data")
	int KeyValue;

	FMakeKeyFNameInt() {}

	explicit FMakeKeyFNameInt(FName Entry, int KeyValue): Entry(Entry), KeyValue(KeyValue) 
	{	}
	
	FString StaticString()
	{
		return Entry.ToString();
	}
	
	FName StaticName()
	{
		return Entry;
	}

	int StaticInteger()
	{
		return Entry;
	}

};

USTRUCT(BlueprintType) struct FMakeTMapFNameInt //Declaration. This behaves like a Dictionary (TMap). Also using since TMap Functions return error in ElementType conversions
{
	GENERATED_BODY()
	
	//
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Data")
	TArray<FMakeKeyFNameInt> MapBase;

	FMakeTMapFNameInt() {}

	explicit FMakeTMapFNameInt(TArray<FMakeKeyFNameInt> MapBase): MapBase(MapBase)
	{	}

	explicit FMakeTMapFNameInt(const FMakeKeyFNameInt Base): MapBase({Base})
	{	}

	explicit FMakeTMapFNameInt(const TArray<FName> Base): MapBase({})
	{
		if (Base.Num())
		{
			for (int X = 0; X < Base.Num(); X++)
			{
				MapBase.Add(FMakeKeyFNameInt(Base[X], 0));
			}
		}
	}

	int FindByEntry(FName Name)
	{
		return UCMAbstractStructs::FindByStaticName<FMakeKeyFNameInt>(MapBase, Name);
	}

	int FindByKey(int Key)
	{
        return UCMAbstractStructs::FindByStaticInteger<FMakeKeyFNameInt>(MapBase, Key); 
	}

	int GetMax()
	{
		if (!MapBase.Num()) return -1;
		int Max = -1;
		int MaxValue = -10000000000000000000;
		for (int X = 0; X < MapBase.Num(); X++)
		{
			if (MapBase[X].KeyValue > MaxValue)
			{
				MaxValue = MapBase[X].KeyValue;
				Max = X;
			}
		}
		return Max;
	}

};

Why you doing this? What you trying to achieve?

I have a set of functions that I want to implement as I’m not content with the current functions given accessible by TMap. I guess that it would better to implement them on a function library (as Templates?); however, I would not fully know how to go on about that. One of the reasons is that I already have templates that look for specific information and with this method I can manually specify what is what (for example, the values inside StaticInteger()) and use those accordingly.