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<InputIterator Iter, Predicate<auto, Iter::value_type> Pred>
12 //   requires CopyConstructible<Pred>
13 //   constexpr Iter   // constexpr after C++17
14 //   find_if_not(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 struct ne {
nene24     TEST_CONSTEXPR ne (int val) : v(val) {}
operator ()ne25     TEST_CONSTEXPR bool operator () (int v2) const { return v != v2; }
26     int v;
27     };
28 
29 #if TEST_STD_VER > 17
test_constexpr()30 TEST_CONSTEXPR bool test_constexpr() {
31     int ia[] = {1, 3, 5, 2, 4, 6};
32     int ib[] = {1, 2, 3, 7, 5, 6};
33     ne c(4);
34     return    (std::find_if_not(std::begin(ia), std::end(ia), c) == ia+4)
35            && (std::find_if_not(std::begin(ib), std::end(ib), c) == ib+6)
36            ;
37     }
38 #endif
39 
main(int,char **)40 int main(int, char**)
41 {
42     int ia[] = {0, 1, 2, 3, 4, 5};
43     const unsigned s = sizeof(ia)/sizeof(ia[0]);
44     input_iterator<const int*> r = std::find_if_not(input_iterator<const int*>(ia),
45                                                     input_iterator<const int*>(ia+s),
46                                                     ne(3));
47     assert(*r == 3);
48     r = std::find_if_not(input_iterator<const int*>(ia),
49                          input_iterator<const int*>(ia+s),
50                          ne(10));
51     assert(r == input_iterator<const int*>(ia+s));
52 
53 #if TEST_STD_VER > 17
54     static_assert(test_constexpr());
55 #endif
56 
57   return 0;
58 }
59