C++ EventHandler class, invoking & arguments This is my EventHandler class, which is extremely simple and can be used on lambdas and similar:

template&lt;typename Signature, typename...Ax&gt;
class Event
{
private:
    typedef std::function&lt;Signature(Ax...)&gt; Function;
    Function _func;

public:

    void CallFunc(Ax... ax)
    {
        if (_func)
        {
            (_func)(ax...);
        }
    }

    void operator+=(Function func)
    {
        _func = func;
    }

};


I'm looking to find improvements as it's basically as simple as it gets.

Example:

Event&lt;void, int&gt; myEvent;
myEvent += [](int arg) { printf("%i", arg); };

myEvent.CallFunc(15);


Would print out 15.
I don't like that you use operator += to set the function. += suggests that I can append a bunch of functions and they all get called when the event happens, which is not the case. myEvent.setFunction([](int){}); would be better.

It would make sense to take advantage of move semantics. The lambda that gets passed into myEvent is moved into func and then copied into _func, when 2 moves would have been enough:

void operator+=(Function func)
{
    _func = std::move(func);
}


Better yet: Make it a template and perfect forward the argument to have only 1 move:

template&lt;class Fun&gt;
void operator+=(Fun &amp;&amp;func)
{
    _func = std::forward&lt;Fun&gt;(func);
}


You get somewhat worse error messages but most likely better performance.

Same goes for CallFunc, it should take a variadic template argument that gets perfect forwarded into the call for efficiency.

Speaking of efficiency, the flexibility of std::function comes at a price. It is known at compile time what types func can be, so _func should be exactly the same type without type erasure and virtual function calls. You can make that work with a template &lt;class Fun&gt; Event&lt;Fun&gt; make_event(Fun &amp;&amp;fun) style function to get the type of the function and create an Event with the appropriate template parameters, but you lose the ability to specify the function later.

There are extra parenthesis in the call (_func)(ax...);. Maybe it is a style thing, but I would write _func(ax...); instead.

Oh, and printf is not very C++y, but it was just an example.