find_if.pass.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <algorithm>
  10. // template<InputIterator Iter, Predicate<auto, Iter::value_type> Pred>
  11. // requires CopyConstructible<Pred>
  12. // Iter
  13. // find_if(Iter first, Iter last, Pred pred);
  14. #include <algorithm>
  15. #include <functional>
  16. #include <cassert>
  17. #include "test_iterators.h"
  18. struct eq {
  19. eq (int val) : v(val) {}
  20. bool operator () (int v2) const { return v == v2; }
  21. int v;
  22. };
  23. int main()
  24. {
  25. int ia[] = {0, 1, 2, 3, 4, 5};
  26. const unsigned s = sizeof(ia)/sizeof(ia[0]);
  27. input_iterator<const int*> r = std::find_if(input_iterator<const int*>(ia),
  28. input_iterator<const int*>(ia+s),
  29. eq(3));
  30. assert(*r == 3);
  31. r = std::find_if(input_iterator<const int*>(ia),
  32. input_iterator<const int*>(ia+s),
  33. eq(10));
  34. assert(r == input_iterator<const int*>(ia+s));
  35. }