Say want to store the following:

typedef std::function<void(int)> MyFunctionDecl;

..in a collection:

typedef std::vector<MyFunctionDecl> FunctionVector;
FunctionVector v;

This is possible, but if I want to find something using std::find:

FunctionVector::const_iterator cit = std::find(v.begin(), v.end(), myFunctionDecl);

.. we get an error due to the == operator.

As has been suggested to me in a previous question concerning this, this can be gotten around by encapsulating the function declaration within another class, which provides a == operator:

class Wrapper
{
private:
    MyFunctionDecl m_Func;

public:
    // ctor omitted for brevity

    bool operator == (const Wrapper& _rhs)
    {
         // are they equal?
    }; // eo ==
};  // eo class Wrapper

So what I want to do is somehow generate a hash for "MyFunctionDecl" so that I can properly implement the == operator. I could have some kind of unique identifier, and ask the caller to provide a unique identifier for the delegate, but this seems a bit of a pain and is error prone.

Is there a way that I can do this? So that the same functions will return the same ID for comparative purposes? So far, the only way around it is to dump the notion of using std::function and go back to using fast delegates which support comparisons. But then I lose the ability to use lambdas.

Any help appreciated!

EDIT

Given the answer below, this is what I have come up with... any caveats I might have missed? I'm in the process of putting it through it's paces now:

class MORSE_API Event : boost::noncopyable
{
public:
    typedef std::function<void(const EventArgs&)> DelegateType;
    typedef boost::shared_ptr<DelegateType&
Edit
Report