count.pass.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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, class T>
  11. // requires HasEqualTo<Iter::value_type, T>
  12. // constexpr Iter::difference_type // constexpr after C++17
  13. // count(Iter first, Iter last, const T& value);
  14. #include <algorithm>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. #include "test_iterators.h"
  18. #if TEST_STD_VER > 17
  19. TEST_CONSTEXPR bool test_constexpr() {
  20. int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
  21. int ib[] = {1, 2, 3, 4, 5, 6};
  22. return (std::count(std::begin(ia), std::end(ia), 2) == 3)
  23. && (std::count(std::begin(ib), std::end(ib), 9) == 0)
  24. ;
  25. }
  26. #endif
  27. int main()
  28. {
  29. int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
  30. const unsigned sa = sizeof(ia)/sizeof(ia[0]);
  31. assert(std::count(input_iterator<const int*>(ia),
  32. input_iterator<const int*>(ia + sa), 2) == 3);
  33. assert(std::count(input_iterator<const int*>(ia),
  34. input_iterator<const int*>(ia + sa), 7) == 0);
  35. assert(std::count(input_iterator<const int*>(ia),
  36. input_iterator<const int*>(ia), 2) == 0);
  37. #if TEST_STD_VER > 17
  38. static_assert(test_constexpr());
  39. #endif
  40. }