Really, the clearest thing might just be to write a for
loop directly:
for (auto &p : participants_) {
if (p != participant)
p->deliver();
}
or the C++03 equivalent:
for (std::set<chat_participant_ptr>::iterator i = participants_.begin();
i != participants_.end(); ++i)
{
if ((*i) != participant)
(*i)->deliver();
}
I don't think using for_each
buys you any generality or expressiveness here, mostly because you're not composing anything you might want to re-use.
If you do find yourself wanting to do something similar regularly, you could write a generic for_each_not_of
. Is that really the case?