fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <iterator>
  5. #include <ciso646>
  6.  
  7. using namespace std;
  8.  
  9. // Possible implementation from http://e...content-available-to-author-only...e.com/w/cpp/algorithm/find
  10. template<class InputIt, class T>
  11. InputIt my_find(InputIt first, InputIt last, const T& value)
  12. {
  13. for (; first != last; ++first)
  14. if (*first == value)
  15. return first;
  16. return last;
  17. }
  18.  
  19. int main() {
  20. vector<bool> b(5,false);
  21.  
  22. #ifdef _LIBCPP_VERSION
  23. cout << "_LIBCPP_VERSION=" << _LIBCPP_VERSION << endl; // 1101 <-> XCode 4.6.3
  24. #endif
  25.  
  26. // show - lambda to show distance of b.begin()->it, it->b.end()
  27. auto show = [&](vector<bool>::iterator it)
  28. { cout << distance(b.begin(), it) << "," << distance(it,b.end()) << endl; };
  29.  
  30. show(b.begin()); // shows 0,5 as expected
  31. show(b.end()); // shows 5,0 as expected
  32. show(find(next(b.begin(), 1), b.end(), true)); // shows 64/-59! should be (5,0)
  33. show(my_find(next(b.begin(), 1), b.end(), true)); // shows 5,0 as expected
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
0,5
5,0
5,0
5,0