Immediately I apologize for such a vague name, I do not know how to briefly describe the task.
Suppose we have a class that performs some kind of work:
class Worker{ public: bool doWork(int arg); }; The doWork method returns true if the job was successful. It is necessary that someone from the existing workers performed the work. For this I want to use std::find_if
struct DoWork{ int arg; explicit DoWork(int arg): arg(arg) {} bool operator()(Worker &worker) const{ return worker.doWork(arg); } }; std::vector<Worker> workers; //... std::find_if(workers.begin(), workers.end(), DoWork(42)); The idea is this. The algorithm will go through the workers until one does the work or they run out. But I am tormented by vague doubts that this can be done. Is there any uncertain behavior here? Will this code always work the same way on different implementations of stl?