I have in essence the following code:
typedef std::function<void ()> fnGlobalChangeEvent;
typedef std::vector<fnGlobalChangeEvent> GlobalTriggers;
inline void ExecuteGlobal(fnGlobalChangeEvent ev)
{
ev();
}
GlobalTriggers triggers;
std::for_each(triggers.begin(), triggers.end(), std::bind(&ExecuteGlobal, _1));
The use of ExecuteGlobal feels totally redundant here, but I can’t find the right syntax to drop out the call.
std::for_each(triggers.begin(), triggers.end(), ExecuteGlobal(_1));
std::for_each(triggers.begin(), triggers.end(), std::bind(_1));
Both fail to compile.
There is also a more complex case:
typedef std::function<void (Zot&)> fnChangeEvent;
typedef std::vector<fnChangeEvent> Triggers;
inline void Execute(fnChangeEvent ev, Zot& zot)
{
ev(zot);
}
Triggers triggers;
std::for_each(triggers.begin(), triggers.end(), std::bind(&Execute, _1, zot));
Is it possible to do without the helper functions in these cases?
Sure, a lambda:
Or even better, range for: