#Issue with creating event unsubscribe functions
13 messages · Page 1 of 1 (latest)
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.
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
yeah thats what I was doing initially but it looked odd for a function called onCursorMove to take an std::any when there's only one possibility to what the event can be
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?
That may work, but honestly, I'd just store a void* to the function at that point
Hmm yeah
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
just as an fyi, the standard does not require that different types have different hash codes, only that type infos for the same type have the same hash code
it's very strongly suggested to be unique, but not required by standard