I'm attempting to create C#-like multicast delegates and events using features from TR1. Or Boost, since boost::function is (mostly) the same as std::tr1::function. As a proof of concept I tried this:
template<typename T1>
class Event
{
private:
typedef std::tr1::function<void (T1)> action;
std::list<action> callbacks;
public:
inline void operator += (action func)
{
callbacks.push_back(func);
}
inline void operator -= (action func)
{
callbacks.remove(func);
}
void operator ()(T1 arg1)
{
for(std::list<action>::iterator iter = callbacks.begin();
iter != callbacks.end(); iter++)
{
(*iter)(arg1);
}
}
};
Which works, sort of. The line callbacks.remove(func)
does not. When I compile it, I get the following error:
error C2451: conditional expression of type 'void' is illegal
Which is caused by line 1194 of the list
header, which is in the remove
function. What is causing this?