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
9 // <algorithm>
10
11 // template<ForwardIterator Iter, EquivalenceRelation<auto, Iter::value_type> Pred>
12 // requires CopyConstructible<Pred>
13 // constexpr Iter // constexpr after C++17
14 // adjacent_find(Iter first, Iter last, Pred pred);
15
16 #include <algorithm>
17 #include <functional>
18 #include <cassert>
19
20 #include "test_macros.h"
21 #include "test_iterators.h"
22
23
24 #if TEST_STD_VER > 17
eq(int a,int b)25 TEST_CONSTEXPR bool eq (int a, int b) { return a == b; }
26
test_constexpr()27 TEST_CONSTEXPR bool test_constexpr() {
28 int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
29 int ib[] = {0, 1, 2, 7, 0, 1, 2, 3};
30
31 return (std::adjacent_find(std::begin(ia), std::end(ia), eq) == ia+2)
32 && (std::adjacent_find(std::begin(ib), std::end(ib), eq) == std::end(ib))
33 ;
34 }
35 #endif
36
main(int,char **)37 int main(int, char**)
38 {
39 int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
40 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
41 assert(std::adjacent_find(forward_iterator<const int*>(ia),
42 forward_iterator<const int*>(ia + sa),
43 std::equal_to<int>()) ==
44 forward_iterator<const int*>(ia+2));
45 assert(std::adjacent_find(forward_iterator<const int*>(ia),
46 forward_iterator<const int*>(ia),
47 std::equal_to<int>()) ==
48 forward_iterator<const int*>(ia));
49 assert(std::adjacent_find(forward_iterator<const int*>(ia+3),
50 forward_iterator<const int*>(ia + sa),
51 std::equal_to<int>()) ==
52 forward_iterator<const int*>(ia+sa));
53
54 #if TEST_STD_VER > 17
55 static_assert(test_constexpr());
56 #endif
57
58 return 0;
59 }
60