15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier
95a83710eSEric Fiselier // <algorithm>
105a83710eSEric Fiselier
115a83710eSEric Fiselier // template<ForwardIterator Iter, EquivalenceRelation<auto, Iter::value_type> Pred>
125a83710eSEric Fiselier // requires CopyConstructible<Pred>
138694428eSMarshall Clow // constexpr Iter // constexpr after C++17
145a83710eSEric Fiselier // adjacent_find(Iter first, Iter last, Pred pred);
155a83710eSEric Fiselier
165a83710eSEric Fiselier #include <algorithm>
175a83710eSEric Fiselier #include <functional>
185a83710eSEric Fiselier #include <cassert>
195a83710eSEric Fiselier
208694428eSMarshall Clow #include "test_macros.h"
215a83710eSEric Fiselier #include "test_iterators.h"
225a83710eSEric Fiselier
238694428eSMarshall Clow
248694428eSMarshall Clow #if TEST_STD_VER > 17
eq(int a,int b)258694428eSMarshall Clow TEST_CONSTEXPR bool eq (int a, int b) { return a == b; }
268694428eSMarshall Clow
test_constexpr()278694428eSMarshall Clow TEST_CONSTEXPR bool test_constexpr() {
288694428eSMarshall Clow int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
298694428eSMarshall Clow int ib[] = {0, 1, 2, 7, 0, 1, 2, 3};
308694428eSMarshall Clow
318694428eSMarshall Clow return (std::adjacent_find(std::begin(ia), std::end(ia), eq) == ia+2)
328694428eSMarshall Clow && (std::adjacent_find(std::begin(ib), std::end(ib), eq) == std::end(ib))
338694428eSMarshall Clow ;
348694428eSMarshall Clow }
358694428eSMarshall Clow #endif
368694428eSMarshall Clow
main(int,char **)37*2df59c50SJF Bastien int main(int, char**)
385a83710eSEric Fiselier {
395a83710eSEric Fiselier int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
405a83710eSEric Fiselier const unsigned sa = sizeof(ia)/sizeof(ia[0]);
415a83710eSEric Fiselier assert(std::adjacent_find(forward_iterator<const int*>(ia),
425a83710eSEric Fiselier forward_iterator<const int*>(ia + sa),
435a83710eSEric Fiselier std::equal_to<int>()) ==
445a83710eSEric Fiselier forward_iterator<const int*>(ia+2));
455a83710eSEric Fiselier assert(std::adjacent_find(forward_iterator<const int*>(ia),
465a83710eSEric Fiselier forward_iterator<const int*>(ia),
475a83710eSEric Fiselier std::equal_to<int>()) ==
485a83710eSEric Fiselier forward_iterator<const int*>(ia));
495a83710eSEric Fiselier assert(std::adjacent_find(forward_iterator<const int*>(ia+3),
505a83710eSEric Fiselier forward_iterator<const int*>(ia + sa),
515a83710eSEric Fiselier std::equal_to<int>()) ==
525a83710eSEric Fiselier forward_iterator<const int*>(ia+sa));
538694428eSMarshall Clow
548694428eSMarshall Clow #if TEST_STD_VER > 17
558694428eSMarshall Clow static_assert(test_constexpr());
568694428eSMarshall Clow #endif
57*2df59c50SJF Bastien
58*2df59c50SJF Bastien return 0;
595a83710eSEric Fiselier }
60