adjacent_find.pass.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <algorithm>
  9. // template<ForwardIterator Iter>
  10. // requires EqualityComparable<Iter::value_type>
  11. // constexpr Iter // constexpr after C++17
  12. // adjacent_find(Iter first, Iter last);
  13. #include <algorithm>
  14. #include <cassert>
  15. #include "test_macros.h"
  16. #include "test_iterators.h"
  17. #if TEST_STD_VER > 17
  18. TEST_CONSTEXPR bool test_constexpr() {
  19. int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
  20. int ib[] = {0, 1, 2, 7, 0, 1, 2, 3};
  21. return (std::adjacent_find(std::begin(ia), std::end(ia)) == ia+2)
  22. && (std::adjacent_find(std::begin(ib), std::end(ib)) == std::end(ib))
  23. ;
  24. }
  25. #endif
  26. int main(int, char**)
  27. {
  28. int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
  29. const unsigned sa = sizeof(ia)/sizeof(ia[0]);
  30. assert(std::adjacent_find(forward_iterator<const int*>(ia),
  31. forward_iterator<const int*>(ia + sa)) ==
  32. forward_iterator<const int*>(ia+2));
  33. assert(std::adjacent_find(forward_iterator<const int*>(ia),
  34. forward_iterator<const int*>(ia)) ==
  35. forward_iterator<const int*>(ia));
  36. assert(std::adjacent_find(forward_iterator<const int*>(ia+3),
  37. forward_iterator<const int*>(ia + sa)) ==
  38. forward_iterator<const int*>(ia+sa));
  39. #if TEST_STD_VER > 17
  40. static_assert(test_constexpr());
  41. #endif
  42. return 0;
  43. }