I have a problem which I can't get my head wrapped around. I have two type definitions for callbacks (used by lambdas later on):
typedef std::function<void(Payload1 Payload)> Callback1;
typedef std::function<void(Payload2 Payload)> Callback2;
Where as Payload1 and Payload2 are different structs containing event payload data. Then I got two arrays (as I am using, those are TArrays, but that doesn't matter), which contain the callbacks:
TArray<Callback1> Callback1Array;
TArray<Callback2> Callback2Array;
And a templated function which should add the callback into the array where it fits in:
template<typename CallbackType>
void SubscribeToEvent(CallbackType Callback)
{
// If CallbackType is Callback1
Callback1Array.Add(Callback);
// Else If CallbackType is Callback2
Callback2Array.Add(Callback);
}
I am not sure how I can express the statements I wrote in the comments. It will obviously fail if it tries to add a Callback2 type into the Callback1 array, so I somehow need to check the type, and only add it into the right array, and don't even try to add it in the others. Is this possible?
Thank you :)