#Issue with creating event unsubscribe functions

13 messages · Page 1 of 1 (latest)

cosmic breach
coarse adderBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

late ocean
#

yeah, you can't do that

#

Honestly, the easy was would be to let you subscribers take an any instead of the concrete event type

#

Though, I'm leery of using std::any, there's probably a better way to do it but I'm not coming up with it off the top of my head

cosmic breach
#

Hmm or maybe instead of a vector of functions, I store a vector of:cpp struct EventCallback { std::any fptr; std::function<std::any const&>; }; and compare func to std::any_cast<void(Class::*)(Event const&)>(callbac.fptr)

#

how does that sound?

late ocean
#

That may work, but honestly, I'd just store a void* to the function at that point

cosmic breach
#

Hmm yeah

cosmic breach
#

I went with the idea of using a parallel array that stores the typeid(funcptr).hash_code() for every callback
and to unsubscribe I iterate over that array to find the index of the hash_code, and assign m_listeners[index] = dormantCallbackFunction

late ocean
#

it's very strongly suggested to be unique, but not required by standard