Skip to content

Instantly share code, notes, and snippets.

@mannewalis
Created November 4, 2015 00:04
Show Gist options
  • Save mannewalis/ae423ad24d297d89749a to your computer and use it in GitHub Desktop.
Save mannewalis/ae423ad24d297d89749a to your computer and use it in GitHub Desktop.
possible solution to registering/deregistering function callbacks using this to disambiguate.
class dispatch
{
public:
void register(void* instance, std::function& callback)
{
auto id = hash(instance, callback.target());
map[id] = callback;
}
void unregister(void* instance, std::function& callback)
{
auto id = hash(instance, callback.target());
auto it = map.find(id);
if (it != map.end())
{
map.erase(it);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment