fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <functional>
  4.  
  5. bool PlanA() { return true; }
  6. bool PlanB() { return true; }
  7. bool PlanC() { return false; }
  8. bool Error() { return true; }
  9.  
  10. int main() {
  11.  
  12. using namespace std;
  13.  
  14. function<bool()> steps[] = { PlanA, PlanB, PlanC, Error,
  15. [](){ return false; } /* sentinal */ };
  16. auto failed_at = begin(steps);
  17. while( (*failed_at++)() )
  18. ;
  19.  
  20. cout << "failed at: " << distance( begin(steps), failed_at ) << endl;
  21. }
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
failed at: 3