title: Equality comparing boost::function with functor.members.func_ptr
body: <p>I'm currently trying to implement an event manager in C++. In principle it keeps a map of event types (<code>uint64_t</code>) to a list of <code>boost::function&lt;void(const IEventDataPtr&amp;)&gt;</code>s.</p>
  <p>User can register new listeners by calling <code>EventManager::add(boost::function&lt;void(const IEventDataPtr&amp;)&gt; delegate, EventType event)</code>. However, a user might want to deregister their listener later. This would involve finding this particular function object and removing it from the respective list.</p>
  <p>I know that <code>boost::function</code> is <a href="https://www.boost.org/doc/libs/1_76_0/doc/html/function/faq.html#id-1.3.17.7.2.1" rel="nofollow noreferrer">generally not comparable</a>. When playing around in the debugger I found that by comparing <code>functor.members.func_ptr</code> I could actually do what I was trying to do. It works as expected for lambdas, <code>boost::bind</code>, static member functions and regular functions. <strong>Is this safe to do? Are there any gotchas?</strong></p>
  <p>My expectation would be for the same object (i.e. the same lambda, function, etc. pp.) to have the same address, that is not shared with others.</p>