I have a list of filter functions. If any of these functions return 'true', I should not process an event further.
std::any_of seems suitable for this use case, but I wish to guarantee that the filter functions are called in the order they have been appended to my list (because of possible side effects they may have). Therefore, if I use std::any_of, I need to know the order it calls the filter functions is deterministic, from begin() to end() of the list.
I have checked the C++ standard on std::any_of and the sequential execution policy, but found no mention of order guarantees. I did not find mention about order guarantees on cppreference, and did not find an answered question similar enough on stackoverflow.
My conclusion is that there are no order guarantees. Although most compilers will probably process the functions in my in order, I should not rely on it.
bool MyClass::event(QEvent* event)
{
std::vector<std::function<bool(QEvent*)> > functionList = getCurrentEventFilters();
const auto bFilter = std::any_of(functionList .begin(),
functionList .end(),
[&event](std::function<bool(QEvent*)> function) {return function(event);});
if (bFilter)
{
return true;
}
return Base::event(event);
}