count_if.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  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::difference_type
  13. // count_if(Iter first, Iter last, Pred pred);
  14. #include <algorithm>
  15. #include <functional>
  16. #include <cassert>
  17. #include "test_iterators.h"
  18. int main()
  19. {
  20. int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
  21. const unsigned sa = sizeof(ia)/sizeof(ia[0]);
  22. assert(std::count_if(input_iterator<const int*>(ia),
  23. input_iterator<const int*>(ia + sa),
  24. std::bind2nd(std::equal_to<int>(),2)) == 3);
  25. assert(std::count_if(input_iterator<const int*>(ia),
  26. input_iterator<const int*>(ia + sa),
  27. std::bind2nd(std::equal_to<int>(),7)) == 0);
  28. assert(std::count_if(input_iterator<const int*>(ia),
  29. input_iterator<const int*>(ia),
  30. std::bind2nd(std::equal_to<int>(),2)) == 0);
  31. }