I have a std::multimap
where values are of type std::function
. Since there is no comparison for std::function
- see this - it seems to be no way to remove a specific element from this multimap. I guess the same is true if you'd like to, for example, remove an element by value from e.g. a std::list
or std::vector
.
My use case is a function which takes a callback an argument (std::function
). The callback should be called when a specific event occurs. However, there could be other circumstances where the callee want to 'deregister' the callback before it have fired.
Initially I though, let me just wrap the std::function
in a struct and insert pointers to this struct in my map. However, this didn't prove feasible as the interface user shouldn't have to wrap callbacks in a struct and store pointer values.
The best idea I have at the moment is returning an id when the callback is registered - which must be stored if the callee want's t to have the option to cancel the callback later on.
Any ideas on my pickle?