Find the Index of the Selected Object
问题 Given an object Foo which has the method bool isChecked() const . Let's say that I have Foo foos[] . I am guaranteed that exactly one element of foos will return true on isChecked() , all others will return false . I'm looking for a clever C++03 way to find the index of the true element. I can do this but it's pretty ugly. Does anyone have something better? distance(foos, find_if(foos, foos + SIZE, mem_fun_ref(&Foo::isChecked))) #include <algorithm> #include <functional> #include <iostream>