adjacent_find.pass.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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<ForwardIterator Iter>
  11. // requires EqualityComparable<Iter::value_type>
  12. // constexpr Iter // constexpr after C++17
  13. // adjacent_find(Iter first, Iter last);
  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[] = {0, 1, 2, 7, 0, 1, 2, 3};
  22. return (std::adjacent_find(std::begin(ia), std::end(ia)) == ia+2)
  23. && (std::adjacent_find(std::begin(ib), std::end(ib)) == std::end(ib))
  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::adjacent_find(forward_iterator<const int*>(ia),
  32. forward_iterator<const int*>(ia + sa)) ==
  33. forward_iterator<const int*>(ia+2));
  34. assert(std::adjacent_find(forward_iterator<const int*>(ia),
  35. forward_iterator<const int*>(ia)) ==
  36. forward_iterator<const int*>(ia));
  37. assert(std::adjacent_find(forward_iterator<const int*>(ia+3),
  38. forward_iterator<const int*>(ia + sa)) ==
  39. forward_iterator<const int*>(ia+sa));
  40. #if TEST_STD_VER > 17
  41. static_assert(test_constexpr());
  42. #endif
  43. }