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