Home | History | Annotate | Download | only in alg.adjacent.find
      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>
     13 //   requires EqualityComparable<Iter::value_type>
     14 //   constexpr Iter  // constexpr after C++17
     15 //   adjacent_find(Iter first, Iter last);
     16 
     17 #include <algorithm>
     18 #include <cassert>
     19 
     20 #include "test_macros.h"
     21 #include "test_iterators.h"
     22 
     23 #if TEST_STD_VER > 17
     24 TEST_CONSTEXPR bool test_constexpr() {
     25     int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
     26     int ib[] = {0, 1, 2, 7, 0, 1, 2, 3};
     27 
     28     return  (std::adjacent_find(std::begin(ia), std::end(ia)) == ia+2)
     29          && (std::adjacent_find(std::begin(ib), std::end(ib)) == std::end(ib))
     30          ;
     31     }
     32 #endif
     33 
     34 int main()
     35 {
     36     int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
     37     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
     38     assert(std::adjacent_find(forward_iterator<const int*>(ia),
     39                               forward_iterator<const int*>(ia + sa)) ==
     40                               forward_iterator<const int*>(ia+2));
     41     assert(std::adjacent_find(forward_iterator<const int*>(ia),
     42                               forward_iterator<const int*>(ia)) ==
     43                               forward_iterator<const int*>(ia));
     44     assert(std::adjacent_find(forward_iterator<const int*>(ia+3),
     45                               forward_iterator<const int*>(ia + sa)) ==
     46                               forward_iterator<const int*>(ia+sa));
     47 
     48 #if TEST_STD_VER > 17
     49     static_assert(test_constexpr());
     50 #endif
     51 }
     52