1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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);
20 #include "test_macros.h"
21 #include "test_iterators.h"
25 TEST_CONSTEXPR
bool eq (int a
, int b
) { return a
== b
; }
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};
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
))
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
));
55 static_assert(test_constexpr());